<?php

//include 'classes/financialClass.php';
include 'controller/taskControllerClass.php';
include_once 'model/commonModel.php';
include 'classes/projectPersonnel.php';
include 'classes/nonLaborExpense.php';
include 'classes/contract.php';
include 'classes/report.php';
include 'classes/strings.php';
include 'classes/financialTotals.php';

class projectModelClass extends commonModel {

//primatives
    public $fy, $submitDate, $humanReadableStatus, $prevSummary, $summaryType, $summarySecurity, $workSecurity, $levelOfSum, $priProgramElement, $priProjectNum, $priTaskAreaNum, $priWorkUnitNum, $contrProgramElementB, $contrProjectNumB, $contrTaskAreaNumB, $contrWorkUnitNumB, $contrProgramElementC, $contrProjectNumC, $contrTaskAreaNumC, $contrWorkUnitNumC, $subjectArea, $fundingOrg, $performanceMethod;
    public $responsibleOrg, $responsibleOrgAddress, $responsiblePerson, $responsiblePersonPhone, $responsiblePersonEmail, $responsiblePersonID, $performingOrg, $performingOrgAddress, $technicalObjective, $approach, $progress, $background, $application;
//objects
    public $tasks, $projectPersonnel, $contracts, $nonLaborExpenses, $notes, $reports;
//model
    public $projectModel, $projectView;

//INIT**********************************************************************
    public function __construct() {
        
    }

    public function init($projectId, $level) {
        $projectResult = executeSelect("SELECT * FROM project WHERE projectID=$projectId");
        $row = mysqli_fetch_array($projectResult);
        $this->initCommonPrimatives($row);
        $this->initUncommonPrimatives($row);
        if ($level != 1) {
//echo 'hello';
            $this->tasks = $this->getProjectTasks();
            $this->projectPersonnel = $this->getProjectPersonnel();
            $this->contracts = $this->getContracts();
            $this->nonLaborExpenses = $this->getNonLaborExpenses();
            $this->notes = $this->getAllNotes();
            $this->reports = $this->getReports();
        }
    }

    public function init2($row, $level) {
        $this->initCommonPrimatives($row);
        $this->initUncommonPrimatives($row);
        if ($level != 1) {
            $this->tasks = $this->getProjectTasks();
            $this->projectPersonnel = $this->getProjectPersonnel();
            $this->contracts = $this->getContracts();
            $this->nonLaborExpenses = $this->getNonLaborExpenses();
        }
    }

    private function initCommonPrimatives($row) {
        $this->ID = $row['projectID'];
//echo "id $this->ID";
        $this->actualCost = $row['actualCost'];
        $this->approvedCost = $row['approvedCost'];
        $this->endDate = $row['endDate'];
        $this->proposedCost = $row['proposedCost'];
        $this->startDate = $row['startDate'];
        $this->status = $row['status'];
        //echo $this->status .'<br>';
        $this->humanReadableStatus = getStatusHumanReadableString($this->status, "project");
        $this->title = $row['title'];
        $this->wbsID = $row['wbsId'];
        $this->wbsString = getWbsString($this->wbsID);
        $this->fy = $row['fy'];
        $this->fundingOrg = $row['fundingOrg'];
        $this->submitDate = $row['submitDate'];
        $this->approach = $row['approach'];
        $this->progress = $row['progress'];
        $this->background = $row['background'];
        $this->technicalObjective = $row['technicalObjective'];
        $this->performingOrg = $row['performingOrg'];
        $this->application = $row['application'];
    }

    private function initUncommonPrimatives($row) {
        $this->prevSummary = $row['prevSummary'];
        $this->summaryType = $row['summaryType'];
        $this->summarySecurity = $row['summarySecurity'];
        $this->workSecurity = $row['workSecurity'];
        $this->levelOfSum = $row['levelOfSum'];
        $this->priProgramElement = $row['priProgramElement'];
        $this->priProjectNum = $row['priProjectNum'];
        $this->priTaskAreaNum = $row['priTaskAreaNum'];
        $this->priWorkUnitNum = $row['priWorkUnitNum'];
        $this->contrProgramElementB = $row['contrProgramElementB'];
        $this->contrProjectNumB = $row['contrProjectNumB'];
        $this->contrTaskAreaNumB = $row['contrTaskAreaNumB'];
        $this->contrWorkUnitNumB = $row['contrWorkUnitNumB'];
        $this->contrProgramElementC = $row['contrProgramElementC'];
        $this->contrProjectNumC = $row['contrProjectNumC'];
        $this->contrTaskAreaNumC = $row['contrTaskAreaNumC'];
        $this->contrWorkUnitNumC = $row['contrWorkUnitNumC'];
        $this->subjectArea = $row['subjectArea'];
        $this->performanceMethod = $row['performanceMethod'];
    }

    public function initSingleProject($row) {
        if ($row) {
            $this->ID = $row['projectID'];
            $this->actualCost = $row['actualCost'];
            $this->approvedCost = $row['approvedCost'];
            $this->endDate = $row['endDate'];
            $this->proposedCost = $row['proposedCost'];
            $this->startDate = $row['startDate'];
            $this->status = $row['status'];
            $this->humanReadableStatus = getStatusHumanReadableString($this->status, "project");
            $this->title = $row['title'];
            $this->wbsID = $row['wbsId'];
            $this->wbsString = getWbsString($this->wbsID);
//instantiate the model
            $this->projectModel = new projectModelClass($this->ID);
            $this->tasks = $this->getProjectTasks();
            $this->projectPersonnel = $this->getProjectPersonnel();
            $this->contracts = $this->getContracts();
            $this->nonLaborExpenses = $this->getNonLaborExpenses();
        }
    }

//DATA**********************************************************************
    function getAllNotes() {
        $array = array();
        //project level
        $notesResult = executeSelect("SELECT * from notes where wbsId=$this->wbsID");
        while ($row = mysqli_fetch_array($notesResult)) {
            $notesObj = new notesClass($row);
            array_push($array, $notesObj);
        }
        $notesResult2 = executeSelect("SELECT * from task where projectId=$this->ID");
        while ($row2 = mysqli_fetch_array($notesResult2)) {
            $wbsID = $row2['wbsID'];
            $taskID = $row2['taskID'];
            $notesResult3 = executeSelect("SELECT * from notes where wbsId=$wbsID");
            //task level
            while ($row3 = mysqli_fetch_array($notesResult3)) {
                $notesObj = new notesClass($row3);
                array_push($array, $notesObj);
            }
            $notesResult4 = executeSelect("SELECT * from subtask where taskID=$taskID");
            //echo "SELECT * from subtask where taskID=$taskID <br>";
            while ($row4 = mysqli_fetch_array($notesResult4)) {
                $wbsID = $row4['wbsID'];
                $notesResult5 = executeSelect("SELECT * from notes where wbsId=$wbsID");
                //echo "SELECT * from notes where wbsId=$wbsID <br>";
                //subtask level
                while ($row5 = mysqli_fetch_array($notesResult5)) {
                    $notesObj = new notesClass($row5);
                    array_push($array, $notesObj);
                }
            }
        }
        return $array;
    }

    function getPercentComplete() {
        if (!$this->tasks) {
            $this->tasks = $this->getProjectTasks();
        }
        $total = 0;
        $numSubtasks = 0;
        foreach ($this->tasks as $task) {
            foreach ($task->subtasks as $subtask) {
                $total += $subtask->percentComplete;
                $numSubtasks++;
            }
        }
        if ($numSubtasks === 0) {
            return 0;
        } else {
            return round($total / $numSubtasks);
        }
    }

    function getApprovedProjects() {
        if (isset($_SESSION['projectSortField'])) {
            $sortOrder = $_SESSION['projectSortOrder'];
            $sortField = $_SESSION['projectSortField'];
            return executeSelect("SELECT * FROM project WHERE status='approved' OR status='approvalFinal' ORDER by $sortField $sortOrder");
        } else {
            return executeSelect("SELECT * FROM project WHERE status='approved' OR status='approvalFinal'");
        }
    }

    function getReports() {
        $array = array();
        $reportResult = executeSelect("SELECT * from projectreport where projectID=$this->ID ORDER by quarter");
        while ($row = mysqli_fetch_array($reportResult)) {
            $obj = new report($row);
            array_push($array, $obj);
        }
        return $array;
    }

    function getProjectReport($quarter) {
        if (!$this->reports) {
            $this->reports = $this->getReports();
        }
        foreach ($this->reports as $report) {
            if (strcmp($report->quarter, $quarter) === 0) {
                return $report;
            }
        }
        echo 'null';
        return NULL;
    }

    function getProjectTasks() {
        $array = array();
        $taskResult = executeSelect("SELECT * FROM task WHERE projectID=$this->ID");
        while ($row = mysqli_fetch_array($taskResult)) {
//empty structure
//echo 'task';
            $taskObj = new taskModelClass();
//filled empty Structure
            $taskObj->init($row);
            array_push($array, $taskObj);
        }
        return $array;
    }

    /**
     * Gets the taskModel object for the given task
     * @param type $taskID
     * @return null
     */
    function getProjectTask($taskID) {
        if (!$this->tasks) {
            $this->tasks = $this->getProjectTasks();
        }
        foreach ($this->tasks as $task) {
            if ($task->ID === $taskID) {
                return $task;
            }
        }
        return NULL;
    }

    function getProjectNonLabor($nonLaborID) {
        if (!$this->nonLaborExpenses) {
            $this->nonLaborExpenses = $this->getNonLaborExpenses();
        }
        foreach ($this->nonLaborExpenses as $expense) {
            if ($expense->nonLaborID === $nonLaborID) {
                return $expense;
            }
        }
        return NULL;
    }

    function getProjectContract($contractID) {
        if (!$this->contracts) {
            $this->contracts = $this->getContracts();
        }
        foreach ($this->contracts as $contract) {
            if ($contract->contractID === $contractID) {
                return $contract;
            }
        }
        return NULL;
    }

    function getProjectPersonnel() {
        $array = array();
//        $ppSelect = "SELECT pp.*, p.name, p.phone, p.email 
//                     FROM person p, projectpersonnel pp 
//                     WHERE projectID=$this->ID AND
//                           p.personID=pp.personID";
        $ppSelect = "SELECT pp.* FROM person p, projectpersonnel pp WHERE pp.projectID=$this->ID AND p.personID=pp.personID";
        $ppResult = executeSelect($ppSelect);
        while ($row = mysqli_fetch_array($ppResult)) {
            $ppObj = new projectPersonnel($row);
            array_push($array, $ppObj);
        }
        return $array;
    }

    function getAiList() {
        $array = array();
        if (!$this->projectPersonnel) {
            $this->projectPersonnel = $this->getProjectPersonnel();
        }
        foreach ($this->projectPersonnel as $person) {
            if (strcmp($person->role, "ai") === 0) {
                array_push($array, $person);
            }
        }
        return $array;
    }

    function getPI() {
        if (!$this->projectPersonnel) {
            $this->projectPersonnel = $this->getProjectPersonnel();
        }
        foreach ($this->projectPersonnel as $person) {
            if (strcmp($person->role, "pi") === 0) {
                return $person;
            }
        }
        return NULL;
    }

    function getContracts() {
        $array = array();
        if (isset($_SESSION['contractSortField'])) {
            $sortOrder = $_SESSION['contractSortOrder'];
            $sortField = $_SESSION['contractSortField'];
            $contractQuery = "SELECT c.* FROM contract c, person p WHERE c.projectId=$this->ID AND c.cor=p.personID ORDER by $sortField $sortOrder";
        } else {
            $contractQuery = "SELECT c.* FROM contract c, person p WHERE c.projectId=$this->ID AND c.cor=p.personID";
        }
        $contractResult = executeSelect($contractQuery);
        while ($row = mysqli_fetch_array($contractResult)) {
            $contractObj = new contract($row);
            array_push($array, $contractObj);
        }
        return $array;
    }

    function getNonLaborExpenses() {
        $array = array();
        $nonLaborQuery = "SELECT * FROM nonlaborcost WHERE projectId=$this->ID";
        $nonLaborResult = executeSelect($nonLaborQuery);
        while ($row = mysqli_fetch_array($nonLaborResult)) {
            $nonLaborObj = new nonLaborExpense($row);
            array_push($array, $nonLaborObj);
        }
        return $array;
    }

    /**
     * 
     * @param type $type Materials and Equipment or Travel and Per Diem
     */
    function getNonlaborExpense($type) {
        if (!$this->nonLaborExpenses) {
            $this->nonLaborExpenses = $this->getNonLaborExpenses();
        }
        foreach ($this->nonLaborExpenses as $expense) {
            if (strcmp($expense->type, $type) === 0) {
                return $expense;
            }
        }
        return NULL;
    }

    static function getProjectsThatThisPersonIsRelatedTo($personID) {
        $sqlSelect = "SELECT p.* FROM projectpersonnel pp, project p WHERE pp.personID=$personID AND pp.projectID=p.projectID";
//$sqlSelect = "SELECT * FROM project";
        $projectResult = executeSelect($sqlSelect);
        $array = array();
//$output .=  "Num rows = $projectResult->num_rows";
//return;
        while ($row = mysqli_fetch_array($projectResult)) {
            $obj = new projectModelClass();
            $obj->init2($row, 1);
            array_push($array, $obj);
        }
        return $array;
    }

    static function getAllProjects($level) {
        $sqlSelect = "SELECT * FROM project";
        $projectResult = executeSelect($sqlSelect);
        $array = array();
        while ($row = mysqli_fetch_array($projectResult)) {
            $obj = new projectModelClass();
            $obj->init2($row, $level);
            array_push($array, $obj);
        }
        return $array;
    }

    static function getApprovedProjectsObjects() {
        $result = getApprovedProjectsData();
        $array = array();
        while ($row = mysqli_fetch_array($result)) {
            $obj = new projectModelClass();
            $obj->init2($row, 1);
            array_push($array, $obj);
        }
        return $array;
    }

    static function getProposals() {
        $result = getProposalsData();
        $array = array();
        while ($row = mysqli_fetch_array($result)) {
            $obj = new projectModelClass();
            $obj->init2($row, 1);
            array_push($array, $obj);
        }
        return $array;
    }

    function getProjectRow() {
        $result = executeSelect("SELECT * FROM project WHERE projectID=$this->ID");
        return mysqli_fetch_array($result);
    }

    function getGradingGivenWbsID($wbsID) {
        $sqlSelect = "SELECT * FROM notes WHERE wbsID=$wbsID AND type='grading' ORDER by personId ASC, subType ASC";
        return executeSelect($sqlSelect);
    }

    function getRequirementsForGivenProject($projectID) {
        $row = mysqli_fetch_array(executeSelect("SELECT fy FROM project WHERE projectID=$projectID"));
        $fy = $row['fy'];
        $reqSelect = "SELECT r.description, r.priority, p.name, st.title AS title
                  FROM task t, subtask st, requirement r, parameter p
                  WHERE t.projectID=$projectID AND 
                        t.taskID=st.taskID AND 
                        st.reqID=r.reqID and r.fiscalYear=$fy AND p.parameterID=st.parameterID";

//$output .=  $reqSelect;
        return executeSelect($reqSelect);
    }

    function duplicateProjectPersonnel($newProjectID) {
        $ppResult = executeSelect("SELECT * FROM projectpersonnel WHERE projectID=$projectID");
        while ($row = mysqli_fetch_array($ppResult)) {
            $personID = $row['personID'];
            $role = $row['role'];
            $insertResult = executeInsert("INSERT into projectpersonnel (personID, projectID, role)
                                                           VALUES ('$personID','$newProjectID','$role')");
            if (!$insertResult) {
                return false;
            }
        }
        return true;
    }

//PROCESSING****************************************************************

    public function processRebaselineSubmitDecisionRequest() {
        $decision = $_POST['submit'];
        if (strpos($decision, "Approve") !== false) {
            $decision = "approve";
//keep original values?????
//
            //move proposedRebaseline => valueProposed
            $success = false;
            foreach ($_POST as $pizza => $value) {
                $pieces = commonModel::parseFinancialTableField($pizza);
                if ($pieces && strlen($value) > 0 && !is_nan(floatval($value)) && sizeof($pieces) >= 5) {
                    $projectID = $pieces[0];
                    $taskID = $pieces[1];
                    $subtaskID = $pieces[2];
                    $type = $pieces[3];
                    $quarter = $pieces[4] + 1;
                    $updateResult = executeUpdate("UPDATE subtaskfinancial SET valueProposed=$value WHERE subtaskID=$subtaskID AND type='$type' AND quarter=$quarter");
                    if ($updateResult) {
                        $success = true;
                    }
                    else
                        return NULL;
                }
            }
            if ($success) {
                updateStatus('approvalFinal', 'project', $projectID);
                $wbsId = getFieldGivenAnID('project', 'projectID', $projectID, 'wbsId');
//echo "UPDATE notes set value='inactive' WHERE wbsId=$wbsId AND subType='rebaselineRequest'";
                $noteResult = executeUpdate("UPDATE notes set value='inactive' WHERE wbsId=$wbsId AND subType='rebaselineRequest'");
                if ($noteResult) {
                    return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Rebaseline Submission Approved";
                } else {
                    echo 'active error';
                }
            }
        } else {
            $decision = "disapprove";
        }
        echo $decision;
    }

    public function processRebaselineSubmitRequest() {
//submit rebaseline button
//print_r($_POST);
        $success = false;
        foreach ($_POST as $pizza => $value) {
            $pieces = commonModel::parseFinancialTableField($pizza);
//echo sizeof($pieces) . '<br>';
            $floatVal = doubleval($value);
//echo 'Value -' . $value . '- ' . strlen($value) . '<br>';
            if ($pieces && strlen($value) > 0 && !is_nan(floatval($value)) && sizeof($pieces) >= 5) {
                $projectID = $pieces[0];
                $taskID = $pieces[1];
                $subtaskID = $pieces[2];
                $type = $pieces[3];
                $quarter = $pieces[4] + 1;
                $updateResult = executeUpdate("UPDATE subtaskfinancial SET proposedRebaseline=$value WHERE subtaskID=$subtaskID AND type='$type' AND quarter=$quarter");
//echo "UPDATE subtaskfinancial SET proposedRebaseline=$value WHERE subtaskID=$subtaskID AND type='$type' AND quarter=$quarter <br>";
                if ($updateResult) {
                    $success = true;
                }
                else
                    return NULL;
            }
        }
        if ($success) {
            updateStatus('rebaselineSubmitRequest', 'project', $projectID);
            return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Rebaseline Submission sent successfully";
        }
    }

    function getNewTaskPage() {
        $output = "";
        $output .= $this->getBasicHeader("New Task");
        $output .= commonModel::getTaskForm();
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function processNewProposalSubmitRequest() {
//print_r($_POST);
//return;
        $submissionType = $_POST['submit'];
//get all of the fields from the form
        $title = $_POST['textFieldTitle'];
        //$submitDate = $_POST['textFieldDateOfSummary'];
        //$submitDate = getMysqlDateFormat($submitDate);
        $submitDate = getMysqlDateFormat(date("m/d/Y"));
        $prevSummary = $_POST['textFieldDateOfPrevSummary'];
        $prevSummary = getMysqlDateFormat($prevSummary);
        //$startDate = getMysqlDateFormat($_POST['textFieldStartDate']);
        //$fy = getFYFromMysqlDateFormatStartDate($startDate);
        $fy = $_POST['fy'];
        //$endDate = getMysqlDateFormat($_POST['textFieldEndDate']);
        $fy--;
        $startDate = getMysqlDateFormat("10/1/$fy");
        $fy++;
        $endDate = getMysqlDateFormat("09/30/$fy");
        $summaryType = $_POST['textFieldTypeOfSummary'];
        $summarySecurity = $_POST['textFieldSummarySecurity'];
        $workSecurity = $_POST['textFieldWorkSecurity'];
        $levelOfSum = $_POST['textFieldLevelOfSum'];
        $priProgramElement = $_POST['textFieldPrimaryProgramElement'];
        $priProjectNum = $_POST['textFieldPrimaryProjectNumber'];
        $priTaskAreaNum = $_POST['textFieldPrimaryTaskAreaNumber'];
        $priWorkUnitNum = $_POST['textFieldPrimaryWorkUnitNumber'];
        $contrProgramElementB = $_POST['textFieldContrProgramElementB'];
        $contrProjectNumB = $_POST['textFieldContrProjectNumberB'];
        $contrTaskAreaNumB = $_POST['textFieldContrTaskAreaNumberB'];
        $contrWorkUnitNumB = $_POST['textFieldContrWorkUnitNumberB'];
        $contrProgramElementC = $_POST['textFieldContrProgramElementC'];
        $contrProjectNumC = $_POST['textFieldContrProjectNumberC'];
        $contrTaskAreaNumC = $_POST['textFieldContrTaskAreaNumberC'];
        $contrWorkUnitNumC = $_POST['textFieldContrWorkUnitNumberC'];
        $subjectArea = $_POST['textFieldSubjectArea'];
        $fundingOrg = $_POST['textFieldFundingOrg'];
        $performanceMethod = $_POST['textFieldPerformMethod'];
        $responsibleOrg = "PEO C4I/PMW 120";
        $responsibleOrgAddress = "PMW-120, 4301 Pacific Highway OT-01 San Diego, CA 92110-3127";
        $responsiblePerson = "Mr. Diallo Wallace";
        $responsiblePersonPhone = "858-537-xxxx";
        $responsiblePersonEmail = "responsiblePerson@email.com";
        $responsiblePersonID = getPersonId($responsiblePerson, $responsiblePersonPhone, $responsiblePersonEmail);
        $performingOrg = $_POST['performingOrgTextField'];
        $performingOrgAddress = "";
        $piName = $_POST['piNameTextField'];
        $piPhone = $_POST['piPhoneTextField'];
        $piEmail = $_POST['piEmailTextField'];
        $piPersonID = getPersonId($piName, $piPhone, $piEmail);
        $application = $_POST['appDropdown'];

        $aiNameList = array();
        $aiPhoneList = array();
        $aiEmailList = array();
        for ($i = 0; $i < 20; $i++) {
            $nameField = 'nameField' . $i;
//echo $nameField . '<br>';
            if (isset($_POST['' . $nameField . ''])) {
                array_push($aiNameList, $_POST['' . $nameField . '']);
//echo 'Name: ' . $_POST['' . $nameField . ''] . '<br>';
                $phoneField = 'phoneField' . $i;
                array_push($aiPhoneList, $_POST['' . $phoneField . '']);
//echo 'Phone: ' . $_POST['' . $phoneField . ''] . '<br>';
                $emailField = 'emailField' . $i;
                array_push($aiEmailList, $_POST['' . $emailField . '']);
            } else {
//break;
            }
        }

//big text areas
        $technicalObjective = $_POST['technicalObjectiveTextArea'];
        $progress = $_POST['progressTextArea'];
        $approach = $_POST['approachTextArea'];
        $background = $_POST['backgroundTextArea'];

//wbs stuff
        $hasWbsChanged = false;
        if (isset($_POST['textFieldWbsID']) && strlen($_POST['textFieldWbsID']) > 0) {
            $wbsString = $this->validateWbs($_POST['textFieldWbsID']);
//echo "wbsTextField: ";
//echo $_POST['textFieldWbsID'];
            $wbsDescription = $_POST['textFieldWbsDescription'];
            $wbsOther = $_POST['textFieldWbsOther'];
        } else {
            $wbsString = getNextProjectWbsAvailable($fy);
            $wbsDescription = "";
            $wbsOther = "";
        }
//NEW PROPOSAL**********************************************************
        if (strcmp($submissionType, "Continue") == 0) {

//check if wbs already exists for this fy
            $wbsIDResult2 = executeSelect("SELECT * FROM wbs WHERE wbsString='$wbsString' and fy=$fy");
            if ($wbsIDResult2 && $wbsIDResult2->num_rows > 0) {
//it is already used so just give it the next available for now
                $wbsString = getNextProjectWbsAvailable($fy);
                $hasWbsChanged = true;
            }
//insert the wbs
            $wbsInsert = "INSERT into wbs (wbsString, description, other, level, fy) values ('$wbsString', '$wbsDescription','$wbsOther',1, $fy)";
            $wbsResult = executeInsert($wbsInsert);
//get the ID of the newly inserted wbs
            $wbsIDResult = executeSelect("SELECT * FROM wbs WHERE wbsString='$wbsString' and fy=$fy");
            $row = mysqli_fetch_array($wbsIDResult);
            $wbsID = $row['wbsID'];
            $curDate = date('Y-m-d');
            $multiyearProjectID = executeInsert("INSERT into multiyearproject (dateCreated) values ('$curDate')");
//insert the project
            $projectQuery = "INSERT into project (title,submitDate, prevSummary, startDate, endDate, summaryType, summarySecurity, workSecurity, levelOfSum, 
                                   priProgramElement, priProjectNum, priTaskAreaNum, priWorkUnitNum, contrProgramElementB, contrProjectNumB, 
                                   contrTaskAreaNumB, contrWorkUnitNumB, contrProgramElementC, contrProjectNumC, contrTaskAreaNumC,  
                                   contrWorkUnitNumC, subjectArea, fundingOrg, performanceMethod, responsibleOrg, responsibleOrgAddress,
                                   performingOrg, performingOrgAddress, status, application, wbsID, technicalObjective, approach,
                                   background, progress, fy, multiyearProjectID) 
                              VALUES ('$title','$submitDate', '$prevSummary', '$startDate', '$endDate', '$summaryType', '$summarySecurity', '$workSecurity', '$levelOfSum', 
                              '$priProgramElement', '$priProjectNum', '$priTaskAreaNum' , '$priWorkUnitNum', '$contrProgramElementB', '$contrProjectNumB',
                              '$contrTaskAreaNumB', '$contrWorkUnitNumB', '$contrProgramElementC'  ,'$contrProjectNumC', '$contrTaskAreaNumC', 
                              '$contrWorkUnitNumC', '$subjectArea', '$fundingOrg', '$performanceMethod', '$responsibleOrg', '$responsibleOrgAddress',
                              '$performingOrg', '$performingOrgAddress','created','$application', '$wbsID', '$technicalObjective', '$approach',
                              '$background', '$progress', '$fy', '$multiyearProjectID')";
            $projectID = executeInsert($projectQuery);
        }
        //EDIT***************************************************************************
        else if (strcmp($submissionType, "Submit Changes") == 0) {
            //UPDATE project
            $projectID = $_POST['projectID'];
            $projectQuery = "UPDATE project SET title='$title',submitDate='$submitDate', prevSummary='$prevSummary', startDate='$startDate', 
                                     endDate='$endDate', summaryType='$summaryType', summarySecurity='$summarySecurity', workSecurity='$workSecurity',
                                     levelOfSum='$levelOfSum', priProgramElement='$priProgramElement', priProjectNum='$priProjectNum', 
                                     priTaskAreaNum='$priTaskAreaNum', priWorkUnitNum='$priWorkUnitNum', contrProgramElementB='$contrProgramElementB', 
                                     contrProjectNumB='$contrProjectNumB', contrTaskAreaNumB='$contrTaskAreaNumB', contrWorkUnitNumB='$contrWorkUnitNumB', 
                                     contrProgramElementC='$contrProgramElementC', contrProjectNumC='$contrProjectNumC', contrTaskAreaNumC='$contrTaskAreaNumC',  
                                     contrWorkUnitNumC='$contrWorkUnitNumC', subjectArea='$subjectArea', fundingOrg='$fundingOrg', performanceMethod='$performanceMethod', 
                                     responsibleOrg='$responsibleOrg', responsibleOrgAddress='$responsibleOrgAddress', fy='$fy',
                                     performingOrg='$performingOrg', performingOrgAddress='$performingOrgAddress', application='$application',
                                     technicalObjective='$technicalObjective', approach='$approach', background='$background', progress='$progress'    
                                     WHERE projectID=$projectID";
            $result = executeUpdate($projectQuery);
        }
        //EDIT OR CREATE****************************************************************
        //This is done regardless of creating or editing
        if ($projectID > 0) {
            //now enter personnel info into the projectPersonnel table
            //INSERT/UPDATE PI
            if (strcmp($submissionType, "Continue") == 0) {
                $sqlInsert = "INSERT into projectpersonnel (projectID, personID, role) values ('$projectID', '$piPersonID', 'pi')";
                //Create empty nonlabor expenses                    
                executeInsert("INSERT into nonlaborcost (type, projectId, proposedCost) values ('Materials and Equipment', $projectID, -1) ");
                executeInsert("INSERT into nonlaborcost (type, projectId, proposedCost) values ('Travel and Per Diem', $projectID, -1) ");
                executeInsert("INSERT into nonlaborcost (type, projectId, proposedCost) values ('Other', $projectID, -1) ");
                //create transition report row
                executeUpdate("INSERT into projectreport (quarter, projectID) values (0, $projectID) ");
            } else if (strcmp($submissionType, "Submit Changes") == 0) {
                $sqlInsert = "UPDATE projectpersonnel set personID='$piPersonID' WHERE projectID='$projectID' AND role='pi'";
            }
            $result = executeUpdate($sqlInsert);
            if ($result) {
                //delete all of the old ai people and just reinsert them
                if (strcmp($submissionType, "Submit Changes") == 0) {
                    $sqlDelete = "DELETE FROM projectpersonnel WHERE projectID='$projectID' AND role='ai'";
                    executeInsert($sqlDelete);
                }
                //INSERT AI List
                for ($i = 0; $i < sizeof($aiNameList); $i++) {
                    $aiName = $aiNameList[$i];
                    $aiPhone = $aiPhoneList[$i];
                    $aiEmail = $aiEmailList[$i];
                    $aiId = getPersonId($aiName, $aiPhone, $aiEmail);
                    $sqlInsert = "INSERT into projectpersonnel (projectID, personID, role) values ('$projectID', '$aiId', 'ai')";
                    $result = executeUpdate($sqlInsert);
                    if (!$result) {
                        echo "Error inserting ai '.$sqlInsert.' <br>";
                        return;
                    }
                }
                //INSERT RESPONSIBLE PERSON
                if (strcmp($submissionType, "Continue") == 0) {
                    $sqlInsert = " INSERT into projectpersonnel (projectID, personID, role) values ('$projectID', '$responsiblePersonID', 'pireviewer')";
                } else if (strcmp($submissionType, "Submit Changes") == 0) {
                    $sqlInsert = " UPDATE projectpersonnel SET personID='$responsiblePersonID' WHERE projectID='$projectID' AND role='pireviewer'";
                } else {
                    $sqlInsert = NULL;
                }
                $result = executeUpdate($sqlInsert);
                if ($result) {//echo $sqlInsert;
                    if ($hasWbsChanged) {
                        return "location:mainPage.php?request=project&action=viewProjectDetails&wbs=$wbsString&projectId=$projectID";
                    } else {
                        if (strcmp($submissionType, "Continue") == 0) {
                            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectID&update=Success - Please add tasks below&activeDiv=tasks";
                        } else {
                            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectID&update=Success";
                        }
                    }
                } else {
                    echo "error inserting responsible person $sqlInsert <br>";
                }
            } else {
                echo "error inserting pi $sqlInsert <br>";
            }
        } else {
//nope
            echo 'Insert project Failed <br> ' . $projectQuery . ' <br>';
        }
    }

    function updateWbsStuff() {
        $projectID = $_POST['projectID'];
        //get the WBSString currently in the db to see if has changed    
        $sqlSelect = "SELECT wbsID FROM project WHERE projectId=$projectID";
        $result2 = executeSelect($sqlSelect);
        $row22 = mysqli_fetch_array($result2);
        $dbWbsID = $row22['wbsID'];
        $wbsStringFromDb = getFieldGivenAnID("wbs", "wbsID", $dbWbsID, "wbsString");
        $dbtartDate = getMysqlDateFormat(getFieldGivenAnID("project", "projectID", $projectID, "startDate"));
        //has wbs changed or fy
        if (strcmp($wbsStringFromDb, $wbsString) !== 0 || strcmp($dbtartDate, $startDate) !== 0) {
            //check to see if it new wbs typed in the textfield is available
            $wbsIDResult = executeSelect("SELECT * FROM wbs WHERE wbsString='$wbsString' and fy=$fy");
            if ($wbsIDResult && $wbsIDResult->num_rows > 0) {
//it is already used so just give it the next available for now
                $wbsString = getNextProjectWbsAvailable($fy);
                $hasWbsChanged = true;
//echo "new wbs $wbsString";
            }
//now update task and subtask wbs strings
            updateProjectWbsStructure($projectID, $fy, $wbsString, $wbsStringFromDb);
//return;
        }
//if it has not changed just update the wbs fields
//else {
//update the project WBS
        $wbsInsert = "UPDATE wbs SET description='$wbsDescription', other='$wbsOther', fy='$fy', level=1 WHERE wbsID='$dbWbsID'";
        $wbsResult = executeUpdate($wbsInsert);
        if (!$wbsResult) {
            echo 'Error updating wbs <br>';
            return;
        }
//}
//get the wbsID?? (this should not have changed since we are just doing an update)
        $wbsIDResult = executeSelect("SELECT * FROM wbs WHERE wbsString='$wbsString' and fy=$fy");
        $row = mysqli_fetch_array($wbsIDResult);
        //$wbsID = $row['wbsID'];
    }

    function validateWbs($wbsString) {
        if (strpos($wbsString, '.') === FALSE) {
            return $wbsString .= ".0";
        }
        return $wbsString;
    }

    /**
     * Updates the status of the given projectID
     * @param type $projectID
     * @param type $status
     * @return type
     */
    function updateProjectStatus($status) {
        $sqlUpdate = "UPDATE project SET status='$status' WHERE projectID=$this->ID";
//$output .=  $sqlUpdate.'<br>';
        return executeUpdate($sqlUpdate);
    }

    /**
     * Grabs the cost of each task adds them up and sets the project cost for the given projectID
     * @param type $projectID
     * @param type $costType (proposedCost, approvedCost, actualCost)
     * @return boolean
     */
    function updateProjectCost($projectID, $costType) {
//query the cost for each subtask
        $result = executeSelect("SELECT $costType, status, duration FROM task WHERE projectID=$projectID");
        $projectCost = 0;
        $projectDuration = 0;
        if ($result) {
//iterate through the tasks and add them up
            while ($row = mysqli_fetch_assoc($result)) {
                $status = $row['status'];
                if (strcmp("inactive", $status) !== 0) {
                    $projectCost += $row["$costType"];
                    $projectDuration += $row['duration'];
                    if ($row["$costType"] == 0) {
                        $this->updateProjectStatus("taskSubmit");
//updateProjectStatus($projectID, "taskSubmit");
                    }
                }
            }
        } else {
            $output .= 'Error finding project ' . $projectID . '<br>';
            return false;
        }
//query non labor costs
        $sqlSelect = "SELECT proposedCost FROM nonlaborcost WHERE projectID=$projectID";
        $result2 = executeSelect($sqlSelect);
        if ($result2) {
//iterate through them and add them up
            while ($row = mysqli_fetch_assoc($result2)) {
                $projectCost += $row['proposedCost'];
            }
        } else {
            $output .= 'Error finding project ' . $projectID . '<br>';
            return false;
        }
        if (executeUpdate("UPDATE project SET $costType=$projectCost, duration=$projectDuration WHERE projectID=$projectID")) {
            return true;
        }
        return false;
    }

    function processRebaselineDecisionRequest() {
//print_r(($_POST));
        $decision = $_POST['group1'];
        $comments = $_POST['textFieldComments'];
        $projectID = $_POST['projectID'];
        $personID = getPersonIDFromUsername(getCurrentUser());
        $this->init($projectID, 2);
//insert a note for this event
        $this->insertNotes($comments, 'project notes', $this->wbsID, $personID, NULL, 'rebaselineDecision');
//change status to ???
        if (strcmp($decision, 'approve') === 0) {
            $newStatus = 'rebaselineRequestApproved';
        } else {
            $newStatus = 'rebaselineRequestDisapproved';
        }
        if ($this->updateProjectStatusStatic($projectID, $newStatus)) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectID&update=Successfully updated project to Rebaseline Request $decision&activeDiv=status";
        } else {
            return NULL;
        }
    }

    function getMultiYearNextFY($multiyearProjectID) {
        $result = executeSelect("SELECT p.fy FROM project p, multiyearProject m WHERE p.projectID=m.projectID AND p.projectID=$multiyearProjectID ORDER BY fy DESC");
        $row = mysqli_fetch_array($result);
        return $row['fy'];
    }

//HTML STUFF********************************************************************
//PAGE**************************************************************************
//NON LABOR*****************************************************************
    function getEditExistingReportPage() {
//print_r($_POST);
//return;
        $index = getIndexClickedGenericList("submit", 4);
        $quarter = $_POST["quarter$index"];
        $report = $this->getProjectReport($quarter);
//header in view class       
        $output = "";
        $output .= $this->getBasicHeader("Report");
        $output .= getFormLinePost("nonLaborSummaryForm", "mainPage.php?request=project&action=processExistingProjectRequest");
        $output .= '<table class="width100" cellspacing="1">';
        $output .= ' <tr class="header">';
        $output .= $this->getTD("QUARTER $quarter REPORT" . '' . getHiddenField('quarter', $quarter), "center");
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        if (isPI()) {
            $output .= $this->getTD(getTextArea("reportTextarea", 8000, $report->filepath, "500") . '' . getHiddenField('projectID', $this->ID));
        } else {
            $output .= $this->getTD($report->filepath);
        }
        $output .= ' </tr>';
        $output .= ' <tr class="grey">';
        if (isPI()) {
            $output .= $this->getTD(getFormInputElement('submit', 'submit', NULL, "Submit Report"), "center");
        }
        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
//footer in view class
    }

    function processSubmitReport() {
        $projectID = $_POST['projectID'];
        $quarter = $_POST['quarter'];
        $report = $_POST['reportTextarea'];
//we will update since these empty reports should be generated when the proposal is approved
        $updateResult = executeUpdate("UPDATE projectreport SET report='$report', status='submitted' WHERE projectID=$projectID AND quarter=$quarter");
        if ($updateResult) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectID";
        } else {
            return NULL;
        }
    }

    function processUploadReport() {
//print_r($_POST);
//return;
        $index = getIndexClickedGenericList("submit", 5);
        $projectID = $_POST['projectID'];
        $quarter = $_POST["quarter$index"];
        if (strcmp($quarter, "0") == 0)
            $savePath = "project/$projectID/tansition/";
        else
            $savePath = "project/$projectID/quarterlyReport/";

        if (strcmp($_POST["submit$index"], "Upload Report") === 0 || strcmp($_POST["submit$index"], "Upload Plan") === 0) {
            $file = "file$index";
            if ($_FILES[$file]["error"] > 0) {
                echo "Error: " . $_FILES["file$index"]["error"] . "<br>";
            } else {
                if (!file_exists($savePath)) {
                    if (mkdir($savePath, 0777, true)) {
//echo "Success <br>";
                    }
                }
                if (file_exists($savePath . $_FILES["file$index"]["name"])) {
                    echo $_FILES["file$index"]["name"] . " already exists. ";
                } else {
                    move_uploaded_file($_FILES["file$index"]["tmp_name"], $savePath . $_FILES["file$index"]["name"]);
//echo "Stored in: " . $savePath . $_FILES["file"]["name"];
                    $filePath = $savePath . '' . $_FILES["file$index"]["name"];
                    if (executeUpdate("UPDATE projectreport SET filepath='$filePath', status='submitted' WHERE quarter=$quarter AND projectID=$projectID")) {
                        if (strcasecmp($quarter, "0") == 0) {
                            return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Upload Successful&activeDiv=transition";
                        } else {
                            return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Upload Successful&activeDiv=reports";
                        }
                    } else {
                        echo 'error';
                    }
                }
            }
        } else {
            //delete it
            if (executeUpdate("UPDATE projectreport SET filepath='', status='none' WHERE quarter=$quarter AND projectID=$projectID")) {
                $filename = $_POST["filename$index"];
                if (unlink($filename)) {
                    if (strcasecmp($quarter, "0") == 0) {
                        return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Deletion Successful&activeDiv=transition";
                    }
                    else
                        return "location:mainPage.php?request=project&projectId=$projectID&action=viewProjectDetails&update=Deletion Successful&activeDiv=reports";
                } else {
                    echo 'error';
                }
            }
        }
    }

    function getNonLaborDetailsPage() {
        $nonLaborId = $_GET['nonLaborId'];
        $nonLaborObj = $this->getProjectNonLabor($nonLaborId);
        $output = $this->getBasicHeader("Non Labor Expense Details");
        $output .= '<br>';
        $output .= '<a href="mainPage.php?request=project&action=viewProjectDetails&projectId=' . $this->ID . '">Back to Project</a>';
        $output .= '<br>';
        $output .= $this->getNonLaborDetailsForm($nonLaborObj);
        $output .= '<br><br>';
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getNonLaborDetailsForm($nonLaborObj) {
        $output = getFormLinePost("nonLaborSummaryForm", "mainPage.php?request=project&action=processExistingProjectRequest");
        $output .= $this->getNonLaborSummaryTable2($nonLaborObj, false);
        $output .= ' <tr class ="fieldLabel">';
        if (strcmp(getUserRole(), "pi") === 0) {
            if (strcmp($this->status, "created") === 0 || strcmp($this->status, "taskSubmit") === 0 || strcmp($this->status, "subtaskSubmit") === 0 || strcmp($this->status, "piFeedback") === 0) {
                $output .= ' <td>' . getFormInputElement("submit", "submit", NULL, "Edit Expense") . '</td>';
                $output .= ' <td colspan="7">' . getFormInputElement("submit", "submit", NULL, "Delete Expense") . ' </td>';
            }
        }
        if (strcmp(getUserRole(), "pireviewer") === 0) {
            if (strcmp($this->status, "submitComplete") === 0) {
//if pi review then allow feedback
                $output .= getHiddenField("wbsID", $this->wbsID);
                $output .= ' <td colspan="1">' . getFormInputElement("submit", "submit", NULL, "Add Notes") . '</td>';
                $output .= ' <td>' . getDropDownMenuText(getNotesTypeArray(), "notesTypeDropdown") . '</td>';
                $output .= ' <td colspan="7">' . getFormInputElement("text", "textFieldNotes", "99%") . ' </td>';
            } else if (strcmp($this->status, "piFeedback") === 0) {
                $output .= ' <td colspan="8">Awaiting feedback from PI</td>';
            } else if (strcmp($this->status, "piApproverSubmit") === 0) {
                $output .= ' <td colspan="8">Awaiting Approval from Approver</td>';
            }
        }
        $output .= '      <input type="hidden" name="projectID" value="' . $this->ID . '">';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getNonLaborSummaryTable2($nonLabor, $showLink) {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Non Labor Expenses</caption>';
        $output .= ' <col width="26%">';
        $output .= ' <tr class="header">';
        $output .= '     <td>Description</td>';
        $output .= '     <td>Type</td>';
        $output .= '     <td>Cost</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        if ($showLink) {
            $output .= ' <td><a class="black" href="mainPage.php?request=project&action=viewNonLaborDetails&projectId=' . $this->ID . '&nonLaborId=' . $nonLabor->nonLaborID . '">' . $nonLabor->description . '</a></td>';
        } else {
            $output .= ' <td>' . $nonLabor->description . '</td>';
        }
        $output .= ' <td>' . $nonLabor->type . '</td>';
        $output .= ' <td>' . $nonLabor->proposedCost . '</td>';
        $output .= '</tr>';
        $output .= getHiddenField("nonLaborId", $nonLabor->nonLaborID);

        return $output;
    }

    function getNewNonLaborPage() {
        $output = $this->getBasicHeader("New Non Labor Expense");
        $output .= $this->getNewNonLaborExpenseForm();
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getEditNonLaborPage() {
        $nonLaborObj = $this->getProjectNonLabor($_POST['nonLaborId']);
        $output = $this->getBasicHeader("Edit Non Labor Expense");
        $output .= $this->getEditNonLaborExpenseForm($nonLaborObj);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getNewNonLaborExpenseForm() {
        $output = "";
        $array = array("Materials and Equipment", "Travel and Per Diem", "Other");
        $output .= getFormLinePostWithOnSubmit("createExpenseForm", "mainPage.php?request=project&action=processNewNonLabor&projectId=$this->ID", "validateNonLabor(this)");
        $output .= '<table class="width40Center" cellspacing="1">';
        $output .= '<caption>New NonLabor Expense</caption>';
        $output .= ' <tr class ="fieldLabel"><td>Type</td><td>Proposed Cost</td></tr>';
        $output .= ' <tr><td>' . getDropDownMenu($array, "dropdownType") . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'costTextfield', '98%') . '</td></tr>';
        $output .= ' <tr class ="fieldLabel"><td>' . getFormInputElement("submit", "submit", NULL, "Submit") . '</td>';
        $output .= '     <td>' . getHiddenField("projectID", $this->ID) . '</td></tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getEditNonLaborExpenseForm($nonLaborObj) {
        $output = "";
        $array = array("Materials and Equipment", "Travel and Per Diem", "Other");
        $output .= getFormLinePostWithOnSubmit("editExpenseForm", "mainPage.php?request=project&action=processExistingProjectRequest&projectId=$this->ID&nonLaborId=$nonLaborObj->nonLaborID", "validateNonLabor(this)");
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>New NonLabor Expense</caption>';
        $output .= ' <tr class ="fieldLabel"><td>Type</td><td>Cost</td></tr>';
        $output .= ' <tr><td>' . getDropDownMenu($array, "dropdownType", $nonLaborObj->type) . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'costTextfield', '98%', $nonLaborObj->proposedCost) . '</td></tr>';
        $output .= ' <tr class ="fieldLabel"><td colspan="3">' . getFormInputElement("submit", "submit", NULL, "Save Expense") . '</td>';
        $output .= '     <td>' . getHiddenField("projectID", $this->ID) . '</td></tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    public function processExistingNonLaborRequest() {
        //print_r($_POST);
        if (isset($_POST['Travel_and_Per_DiemCostTextfield'])) {
            $travelCost = $_POST['Travel_and_Per_DiemCostTextfield'];
            //echo $travelCost.'<br>';
            $nonLaborId = $_POST['Travel_and_Per_DiemnonLaborId'];
            //echo $nonLaborId.'<br>';
            if (strlen($travelCost) > 0 && !is_nan(floatval($travelCost))) {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=$travelCost WHERE nonLaborCostId=$nonLaborId AND type='Travel and Per Diem'");
                //echo 'good<br>';
            } else {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=0 WHERE nonLaborCostId=$nonLaborId AND type='Travel and Per Diem'");
                //echo '0<br>';
            }
        }
        if (isset($_POST['Materials_and_EquipmentCostTextfield'])) {
            $materialsCost = $_POST['Materials_and_EquipmentCostTextfield'];
            $nonLaborId = $_POST['Materials_and_EquipmentnonLaborId'];
            if (strlen($materialsCost) > 0 && !is_nan(floatval($materialsCost))) {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=$materialsCost WHERE nonLaborCostId=$nonLaborId AND type='Materials and Equipment'");
            } else {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=0 WHERE nonLaborCostId=$nonLaborId AND type='Materials and Equipment'");
            }
        }
        if (isset($_POST['OtherCostTextfield'])) {
            $otherCost = $_POST['OtherCostTextfield'];
            $nonLaborId = $_POST['OthernonLaborId'];
            if (strlen($otherCost) > 0 && !is_nan(floatval($otherCost))) {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=$otherCost WHERE nonLaborCostId=$nonLaborId AND type='Other'");
            } else {
                $nonlaborResult = executeUpdate("UPDATE nonlaborcost SET proposedCost=0 WHERE nonLaborCostId=$nonLaborId AND type='Other'");
            }
        }

        $updateProjectCost = $this->updateProjectCost($this->ID, "proposedCost");
        projectModelClass::updateNewProjectStatusFromOldStatic($this->ID);
        if ($updateProjectCost) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$this->ID&update=Expense(s) saved successfully&activeDiv=status";
        } else {
            return NULL;
        }
    }

    public function processNewNonLaborRequest() {
        $type = $_POST['dropdownType'];
        $cost = $_POST['costTextfield'];
        $nonlaborResult = executeUpdate("INSERT into nonlaborcost (type, proposedCost, projectId) values ('$type',$cost,$this->ID)");
        $updateProjectCost = $this->updateProjectCost($this->ID, "proposedCost");
        if ($nonlaborResult && $updateProjectCost) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$this->ID";
        } else {
            return NULL;
        }
    }

    public function processDeleteNonLaborRequest() {
        $nonLaborId = $_POST['nonLaborId'];
        $projectID = $_POST['projectID'];
        $deleteResult = executeDelete("DELETE FROM nonlaborcost WHERE nonLaborCostId=$nonLaborId");
        if ($deleteResult) {
            $this->updateProjectCost($projectID, "proposedCost");
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$this->ID";
        } else {
            echo 'Error deleting NonLabor <br>';
        }
    }

//CONTRACT******************************************************************
    function getContractDetailsPage() {
        $contractId = $_GET['contractId'];
        $contractObj = $this->getProjectContract($contractId);
        $output = "";
        $output .= $this->getBasicHeader("Contract details");
        $output .= '<br>';
        $output .= '<a href="mainPage.php?request=project&action=viewProjectDetails&projectId=' . $this->ID . '">Back to Project</a>';
        $output .= '<br>';
        $output .= $this->getContractDetailsForm($contractObj);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getContractDetailsForm($contractObj) {
        $output = getFormLinePost("contractSummaryForm", "mainPage.php?request=project&action=processExistingProjectRequest");
        $output .= $this->getContractSummaryTable2($contractObj, false);
        $output .= ' <tr class ="fieldLabel">';
        if (strcmp(getUserRole(), "pi") === 0) {
            if (strcmp($this->status, "submitComplete") !== 0 && strcmp($this->status, "piApproverSubmit") !== 0) {
                $output .= ' <td>' . getFormInputElement("submit", "submit", NULL, "Edit Contract") . '</td>';
                $output .= ' <td colspan="7">' . getFormInputElement("submit", "submit", NULL, "Delete Contract") . '</td>';
            }
        }
        if (strcmp(getUserRole(), "pireviewer") === 0) {
            if (strcmp($this->status, "submitComplete") === 0) {
//if pi review then allow feedback
                $output .= getHiddenField("wbsID", $this->wbsID);
                $output .= ' <td colspan="1">' . getFormInputElement("submit", "submit", NULL, "Add Notes") . ' </td>';
                $output .= ' <td>' . getDropDownMenuText(getNotesTypeArray(), "notesTypeDropdown") . '</td>';
                $output .= ' <td colspan="7">' . getFormInputElement("text", "textFieldNotes", "99%") . ' </td>';
            } else if (strcmp($status, "piFeedback") === 0) {
                $output .= ' <td colspan="8">Awaiting feedback from PI</td>';
            } else if (strcmp($status, "piApproverSubmit") === 0) {
                $output .= ' <td colspan="8">Awaiting Approval from Approver</td>';
            }
        }
        $output .= '      <input type="hidden" name="projectID" value="' . $this->ID . '"></tr>';
        $output .= getHiddenField("contractId", $contractObj->contractID);
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getContractSummaryTable2($contractObj, $showLink = NULL) {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Contracts</caption>';
        $output .= ' <col width="16%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>Contract Number</td>';
        $output .= '     <td>Contractor</td>';
        $output .= '     <td>COR</td>';
        $output .= '     <td>Email</td>';
        $output .= '     <td>Phone</td>';
        $output .= '     <td>POP Start</td>';
        $output .= '     <td>POP End</td>';
        $output .= '     <td>Amount</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        if (!$showLink) {
            $output .= "<td>$contractObj->contractNumber</td>";
        } else {
            $output .= ' <td><a class="black" href="mainPage.php?request=project&action=viewContractDetails&projectId=' . $this->ID . '&contractId=' . $contractObj->contractID . '">' . $contractObj->contractNumber . '</a></td>';
        }
        $output .= "<td>$contractObj->contractor</td>";
        $output .= ' <td>' . $contractObj->name . '</td>';
        $output .= ' <td>' . $contractObj->email . '</td>';
        $output .= ' <td>' . $contractObj->phone . '</td>';
        $output .= ' <td>' . $contractObj->startDate . '</td>';
        $output .= ' <td>' . $contractObj->endDate . '</td>';
        $output .= ' <td>' . $contractObj->amount . '</td>';
        $output .= getHiddenField("contractNumber", $contractObj->contractNumber);
        $output .= ' </tr>';
        return $output;
    }

    function getNewContractPage() {
        $output = $this->getContractHeader("New Contract");
        $output .= $this->getNewContractForm();
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getContractHeader($title) {
        $output = getNewHtmlUpToMeta();
        $output .= getMantisCSSLine();
        $output .= getJavascriptFileLine("js/formValidation.js");
        $output .= getSubtaskDatepicker($this->startDate, $this->endDate);
        $output .=getTitle($title);
        $output .= getCloseTag("head");
        $output .= getOpenTag("body");
        $output .= getLogoLine();
        $output .= getPiMenu();
        $output .= '<br><br>';
        return $output;
    }

    function getNewContractForm() {
        $output = getFormLinePostWithOnSubmit("createExpenseForm", "mainPage.php?request=project&action=processNewContract", "validateContract(this)");
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>New Contract</caption>';

        $output .= ' <tr class ="fieldLabel"><td>Contract Number</td><td>POP Start</td><td>POP End</td><td>Amount</td></tr>';
        $output .= ' <tr>';
        $output .= '     <td>' . getFormInputElement("text", 'contractNumberTextfield', '98%') . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'popStartTextfield', '98%', NULL, NULL, "from") . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'popEndTextfield', '98%', NULL, NULL, "to") . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'amountTextfield', '98%') . '</td></tr>';

        $output .= ' <tr class ="fieldLabel"><td>Contractor</td><td>COR Name</td><td>Phone</td><td>Email</td></tr>';
        $output .= ' <tr>';
        $output .= '     <td>' . getFormInputElement("text", 'contractorTextfield', '98%') . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'corNameNumberTextfield', '98%') . '     </td>';
        $output .= '     <td>' . getFormInputElement("text", 'phoneTextfield', '98%') . '     </td>';
        $output .= '     <td>' . getFormInputElement("text", 'emailTextfield', '98%') . '     </td></tr>';
        $output .= ' <tr class ="fieldLabel"><td colspan="2">' . getFormInputElement("submit", "submit", NULL, "Submit") . '     </td>';
        $output .= '     <td colspan="2"><input type="hidden" name="projectID" value="' . $this->ID . '"></td></tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getEditContractPage() {
        $contractId = $_POST['contractId'];
        $contractObj = $this->getProjectContract($contractId);
        $output = $this->getContractHeader("Edit Contract");
        $output .= $this->getEditContractForm($contractObj);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getEditContractForm($contractObj) {
        $output = getFormLinePostWithOnSubmit("createExpenseForm", "mainPage.php?request=project&action=processExistingContract", "validateContract(this)");
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Edit Contract</caption>';
        $output .= ' <tr class ="fieldLabel"><td>Contract Number</td><td>POP Start</td><td>POP End</td><td>Amount</td></tr>';
        $output .= ' <tr>';
        $output .= '     <td>' . getFormInputElement("text", 'contractNumberTextfield', '98%', $contractObj->contractNumber) . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'popStartTextfield', '98%', $contractObj->startDate, NULL, "from") . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'popEndTextfield', '98%', $contractObj->endDate, NULL, "to") . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'amountTextfield', '98%', $contractObj->amount) . '</td></tr>';
        $output .= ' <tr class ="fieldLabel"><td>Contractor</td><td>COR Name</td><td>Phone</td><td>Email</td></tr>';
        $output .= ' <tr>';
        $output .= '     <td>' . getFormInputElement("text", 'contractorTextfield', '98%', $contractObj->contractor) . '</td>';
        $output .= '     <td>' . getFormInputElement("text", 'corNameNumberTextfield', '98%', $contractObj->name) . '     </td>';
        $output .= '     <td>' . getFormInputElement("text", 'phoneTextfield', '98%', $contractObj->phone) . '     </td>';
        $output .= '     <td>' . getFormInputElement("text", 'emailTextfield', '98%', $contractObj->email) . '     </td></tr>';
        $output .= ' <tr class ="fieldLabel"><td colspan="3">' . getFormInputElement("submit", "submit", NULL, "Save Contract") . '     </td>';
        $output .= '     <td><input type="hidden" name="projectID" value="' . $this->ID . '"></td></tr>';
        $output .= getHiddenField("contractId", $contractObj->contractID);
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function processDeleteContractRequest() {
        $projectID = $_POST['projectID'];
        $contractId = $_POST['contractId'];
        $deleteResult = executeDelete("DELETE FROM contract WHERE projectID=$projectID AND contractId=$contractId");
        if ($deleteResult) {
            header("location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectID");
        } else {
            echo 'Error deleting Contract <br>';
        }
    }

    public function processNewContractRequest() {
        $projectID = $_POST['projectID'];
        $contractNumber = $_POST['contractNumberTextfield'];
        $contractor = $_POST['contractorTextfield'];
        $popStart = getMysqlDateFormat($_POST['popStartTextfield']);
        $popEnd = getMysqlDateFormat($_POST['popEndTextfield']);
        $amount = $_POST['amountTextfield'];
        $name = $_POST['corNameNumberTextfield'];
        $email = $_POST['emailTextfield'];
        $phone = $_POST['phoneTextfield'];
        $personId = getPersonID($name, $phone, $email);
        $contractResult = executeUpdate("INSERT into contract (contractNumber,popStart,popEnd,amount,projectId,cor,contractor) values ('$contractNumber','$popStart','$popEnd',$amount,$projectID,$personId,'$contractor')");
        if ($contractResult) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$this->ID&update=Contract Created Successfully&activeDiv=contracts";
        } else {
            return NULL;
        }
    }

    public function processExistingContractRequest() {
        $contractNumber = $_POST['contractNumberTextfield'];
        $popStart = getMysqlDateFormat($_POST['popStartTextfield']);
        $popEnd = getMysqlDateFormat($_POST['popEndTextfield']);
        $contractor = $_POST['contractorTextfield'];
        $amount = $_POST['amountTextfield'];
        $name = $_POST['corNameNumberTextfield'];
        $email = $_POST['emailTextfield'];
        $phone = $_POST['phoneTextfield'];
        $personId = getPersonID($name, $phone, $email);
        $contractId = $_POST['contractId'];
        $contractResult = executeUpdate("UPDATE contract SET contractNumber='$contractNumber', popStart='$popStart', popEnd='$popEnd', amount=$amount, cor=$personId, contractor='$contractor' WHERE contractId='$contractId'");
        if ($contractResult) {
            return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$this->ID&update=Contract updated successfully&activeDiv=contracts";
        } else {
            return NULL;
        }
    }

//PROJECT*******************************************************************
    function getEditProjectPage() {
        $output = "";
        $fy = $this->fy;
        $output .= $this->getBasicHeader('Edit Project', true);
        $output .= '<br>';
        $output .= '<br>';
        $output .= $this->getProjectForm("edit", $fy, $this);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getproposeProjectRequestPage() {
        $output = "";
        $fy = $_POST['fyDropdown'];
//        $output .= getNewHtmlUpToMeta();
//        $output .= getMantisCSSLine();
        //$output .= getDatepickerStuff();
//        $output .= getTitle("Propose Project");
//        $output .= getCloseTag("head");
//        $output .= getOpenTag("body");
//        $output .= getLogoLine();
//        $output .= getLoggedInAsLine();
        $output .= $this->getBasicHeader("Propose Project Form", true);
        //$output .= getMenuBar(getUserRole());
        $output .= '<br>';
        $output .= '<br>';
        $output .= $this->getProjectForm("create", $fy);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getproposeProjectRequestSelectYearPage() {
        $output = "";
        $output .= $this->getBasicHeader("Select Project Execution Year");
        $output .= '<br>';
        $output .= '<br>';
//have user submit a Fiscal Year
//$output .= getFiscalYearSubmitForm("createProjectWithJs.php", "Start Proposal", "New Project Proposal", "getReqTable(this.value)");
        $output .= $this->getFiscalYearSubmitForm("mainPage.php?request=project&action=proposeProjectRequest", "Start Proposal", "New Project Proposal", "getReqTable(this.value)");
        if (isset($_GET['duplicate'])) {
            $output .= '<br>';
            $output .= 'Project already exists for the selected FY --change to senter and red later';
        }
        $output .= '<br>';
//        $output .= getPreviousProjectSelectForm($_SESSION['username'], "Previous Project");
        $output .= '<br>';
        $output .= '<div id="reqBox">';
        $output .= '</div>';
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getProjectDetailsPage($projectObj, $activeDiv) {
        $output = "";
        $output .= $this->getBasicHeader("Project Details");
        $output .= $this->getProjectStartOfOrderedList($projectObj->title);
        //indicates to user a request is successful or not (frog)
        if (isset($_GET['update'])) {
            $output .= $this->getFlagListItem($_GET['update']);
        }

        if (isProjectInApprovedState($this->status) && !$this->isStatus('submitComplete')) {
            if (strcmp($activeDiv, "financial") === 0) {
                $output .= $this->getProjectfinancialsDiv($projectObj, true);
            } else {
                $output .= $this->getProjectfinancialsDiv($projectObj, false);
            }
            if (strcmp($activeDiv, "reports") === 0) {
                $output .= $this->getProjectReportsDiv($projectObj, true);
            } else {
                $output .= $this->getProjectReportsDiv($projectObj, false);
            }
        }
        if (strcmp($activeDiv, "status") === 0 || (isPI() && $this->isStatus('rebaselineRequestApproved')) ||
                (!isPI() && $this->isStatus('rebaselineRequest')) || (!isPI() && $this->isStatus('rebaselineSubmitRequest')) ||
                $this->isStatus('created') || $this->isStatus('taskSubmit') || $this->isStatus('piFeedback') ||
                $this->isStatus('approved') || $this->isStatus('nonlaborRequired')) {
            $output .= $this->getProjectStatusDiv($projectObj, true);
        } else {
            $output .= $this->getProjectStatusDiv($projectObj, false);
        }
//        if (strcmp($activeDiv, "req") === 0) {
//            $output .= $this->getProjectRequirementDiv($projectObj, true);
//        } else {
//            $output .= $this->getProjectRequirementDiv($projectObj, false);
//        }
        if (strcmp($activeDiv, "details") === 0) {
            $output .= $this->getProjectDetailsDiv($projectObj, true);
        } else {
            $output .= $this->getProjectDetailsDiv($projectObj, false);
        }
        if (strcmp($activeDiv, "tasks") === 0 || $this->isStatus('created') || $this->isStatus('taskSubmit')) {
            $output .= $this->getProjectTasksDiv($projectObj, true);
        } else {
            $output .= $this->getProjectTasksDiv($projectObj, false);
        }
        if (strcmp($activeDiv, "nonLabor") === 0 || $this->isStatus('nonlaborRequired')) {
            $output .= $this->getProjectNonLaborDiv($projectObj, true);
        } else {
            $output .= $this->getProjectNonLaborDiv($projectObj, false);
        }
        if (strcmp($activeDiv, "contracts") === 0) {
            $output .= $this->getProjectContractsDiv($projectObj, true);
        } else {
            $output .= $this->getProjectContractsDiv($projectObj, false);
        }
        if (strcmp($activeDiv, "transition") === 0) {
            $output .= $this->getProjectTransitionDiv($projectObj, true);
        } else {
            $output .= $this->getProjectTransitionDiv($projectObj, false);
        }
        if (strcmp($activeDiv, "notes") === 0 || $this->isStatus('piFeedback')) {
            $output .= $this->getProjectFeedbackDiv($projectObj, true);
        } else {
            $output .= $this->getProjectFeedbackDiv($projectObj, false);
        }
        if (!isPI()) {
            if (strcmp($activeDiv, "grading") === 0 || $this->isStatus('piFeedback')) {
                $output .= $this->getProjectGradingDiv(true);
            } else {
                $output .= $this->getProjectGradingDiv(false);
            }
        }
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getProjectRebaselinePage() {
        $output = "";
        $output .= $this->getBasicHeader("Rebaseline Form");
        if (isPI()) {
            $output .= getFormLinePost("rebaselineForm", "mainPage.php?request=project&action=processRebaselineSubmit");
        } else {
            $output .= getFormLinePost("rebaselineForm", "mainPage.php?request=project&action=processRebaselineSubmitDecision");
        }
        $output .= $this->getFinancialsCurrentYearTable($this);
        if (isPI()) {
            $output .= '<br><table class="width20Center"><tr><td> ' . getFormInputElement('submit', 'submit', '100%', 'Submit Rebaseline') . '</td></tr></table>';
        } else {
            $output .= '<br><table class="width40Center"><tr>';
            $output .= '<td> ' . getFormInputElement('submit', 'submit', '100%', 'Approve Rebaseline Submission') . '</td>';
            $output .= '<td> ' . getFormInputElement('submit', 'submit', '100%', 'Disapprove Rebaseline Submission') . '</td>';
            $output .= '</tr></table>';
        }
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

//DIV***************************************************************************

    function getProjectRequirementDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'projectReqDiv\')" class="buttonExpandCollapse" ' . getTooltip("requirementsButton") . '>REQUIREMENTS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="projectReqDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="projectReqDiv">';
        }
// $row1 = mysqli_fetch_array($projectResult);
        $output .= $this->getRequirementTable($projectObj);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectTransitionDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'projectTransitionDiv\')" class="buttonExpandCollapse" ' . getTooltip("transitionPlanButton") . '>TRANSITION PLAN</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="projectTransitionDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="projectTransitionDiv">';
        }
        $output .= '<br>';
        $output .= $this->getTransitionReportForm();
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectReportsDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'projectReportsDiv\')" class="buttonExpandCollapse" ' . getTooltip("reportsButton") . '>REPORTS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="projectReportsDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="projectReportsDiv">';
        }
        $output .= '<br>';
        $output .= $this->getReportsForm();
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectStatusDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'projectStatusDiv\')" class="buttonExpandCollapse" ' . getTooltip("projectStatusButton") . '>PROJECT STATUS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="projectStatusDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="projectStatusDiv">';
        }
        $output .= $this->getSingleProjectStatusForm($projectObj);
//If a rebaseline request was sent and the user is not the PI then show the approve/disapprove form
        if (strcmp($this->status, 'rebaselineRequest') === 0 && !isPI()) {
            $output .= '<br>';
            $output .= $this->getRebaselineRequestForm();
        }
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectDetailsDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'projectDiv\')" class="buttonExpandCollapse" ' . getTooltip("projectDetailsButton") . '>PROJECT DETAILS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="projectDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="projectDiv">';
        }
        $output .= '<br>';
        $output .= $this->getProjectForm("view", NULL, $projectObj);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectGradingDiv($active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'gradingDiv\')" class="buttonExpandCollapse" ' . getTooltip("projectGradingButton") . '>PROJECT GRADING</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="gradingDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="gradingDiv">';
        }
        $grades = $this->getNotes('grading');
        $output .= '<br>' . $this->getRedText("1-10 (1-lowest and 10-highest)");
        $output .= $this->getGradingForm($grades);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectReviewerNotesDiv($projectResult, $taskResult, $subtaskResult, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'reviewerNotesDiv\')" class="buttonExpandCollapse" ' . getTooltip("reviewerNotesButton") . '>REVIEWER NOTES</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="reviewerNotesDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="reviewerNotesDiv">';
        }
        getFeedbackForm($projectResult, NULL, "Project Notes");
        $output .= '<br>';
        getFeedbackForm($taskResult, NULL, "Task Notes", true);
        $output .= '<br>';
        getFeedbackForm($subtaskResult, NULL, "Subtask Notes", true);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectFeedbackDiv($projectObj, $active = NULL) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'feedbackDiv\')" class="buttonExpandCollapse" ' . getTooltip("piFeedbackButton") . '>PROJECT NOTES</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="feedbackDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="feedbackDiv">';
        }
        $output .= $this->getNotesFormFromObject($this->getNotes('Feedback'), NULL, "Feedback", true);
        $output .= $this->getNotesFormFromObject($this->getNotes('Reviewer Notes'), NULL, "Reviewer Notes");
        $output .= $this->getNotesFormFromObject($this->getNotes('PI Notes'), NULL, "PI Notes");

        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectTasksDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'taskDiv\')" class="buttonExpandCollapse" ' . getTooltip("tasksButton") . '>TASKS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="taskDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="taskDiv">';
        }
        $output .= $this->getTaskSummaryForm($projectObj);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectNonLaborDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'nonlaborDiv\')" class="buttonExpandCollapse" ' . getTooltip("nonLaborButton") . '>NON LABOR EXPENSES</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="nonlaborDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="nonlaborDiv">';
        }
        $output .= $this->getNonLaborSummaryForm($projectObj);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectContractsDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'contractDiv\')" class="buttonExpandCollapse" ' . getTooltip("contractsButton") . '>CONTRACTS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="contractDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="contractDiv">';
        }
        $output .= $this->getContractSummaryForm($projectObj);
        $output .= '</div></li>';
        $output .= '<br>';
        return $output;
    }

    function getProjectfinancialsDiv($projectObj, $active) {
        $output = "";
        $output .= '<li><button value="press" onclick="ToggleList(\'financialDiv\')" class="buttonExpandCollapse" ' . getTooltip("financialsButton") . '>FINANCIALS</button>';
        if ($active) {
            $output .= '<div class = "divInfo" id="financialDiv" style="display:block">';
        } else {
            $output .= '<div class = "divInfo" id="financialDiv">';
        }
        $output .= $this->getProjectFinancialsForm($projectObj);
//$output .= '<br>' . $this->getNonLaborFinancialTable() . '<br>';
        $output .= '<br>' . $this->getStatusColorLegendTable();
        $output .= '</div></li><br>';
        return $output;
    }

//FORMS*************************************************************************

    function getContractSummaryForm($projectObj) {
        $output = "";
        $output .= getFormLinePost("contractSummaryForm", "mainPage.php?request=project&action=proposeNewContractRequest");
        $output .= $this->getContractSummaryTable($projectObj, true);
        $output .= ' <tr class ="fieldLabel">';
        $output .= ' <td colspan="8">';
        if (strcmp(getUserRole(), "pi") === 0) {
            if (!isProjectInApprovedState($projectObj->status)) {
                $output .= getFormInputElement("submit", "submit", NULL, "Add Contract");
            }
        }
        $output .= ' </td>';
        $output .= '      <input type="hidden" name="projectID" value="' . $projectObj->ID . '">';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getNonLaborSummaryForm($projectObj) {
        $output = "";
        $output .= getFormLinePost("nonLaborSummaryForm", "mainPage.php?request=project&action=processExistingProjectRequest&projectId=$projectObj->ID");
        $output .= $this->getNonLaborSummaryTable($projectObj, true);
        $output .= ' <tr class ="fieldLabel">';
        $output .= ' <td colspan="8">';
//        if (strcmp(getUserRole(), "pi") === 0) {
//            if (strcmp($projectObj->status, "created") === 0 || strcmp($projectObj->status, "taskSubmit") === 0 || strcmp($projectObj->status, "subtaskSubmit") === 0 || strcmp($projectObj->status, "piFeedback") === 0) {
//                $output .= getFormInputElement("submit", "submit", NULL, "Add Expense");
//            }
//        }
        $output .= ' </td>';
        $output .= '      <input type="hidden" name="projectID" value="' . $projectObj->ID . '">';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getTaskSummaryForm($projectObj) {
        $output = "";
        $output .= getFormLinePost("taskSummaryForm", " mainPage.php?request=project&action=proposeNewTaskRequest&projectID=$projectObj->ID");
        $output .= $this->getTaskSummaryTable($projectObj);
        $output .= ' <tr class ="fieldLabel">';
        $output .= ' <td colspan="8">';

        if (strcmp(getUserRole(), "pi") === 0) {
            if (!isProjectInApprovedState($this->status)) {
                $output .= getFormInputElement("submit", "submit", NULL, "Add Task", NULL, NULL, getTooltip('addTaskButton'));
            }
        }
        $output .= ' </td>';
        $output .= '      <input type="hidden" name="projectID" value="' . $projectObj->ID . '">';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getPreviousProjectSelectForm($user = NULL, $caption = NULL) {
        $output = "";
        $output .= '<div class="centered">';
        $output .= getFormLinePost("fySubmitForm", "editProjectController.php");
        $output .= '<table  class="width20Center" cellspacing="1">';
        if ($caption) {
            $output .= '<caption>' . $caption . '</caption>';
        } else {
            $output .= '<caption>Select Project</caption>';
        }
        $output .= ' <tr class ="fieldLabel"><td>Title</td>';
        $output .= '     <td class="center">';
        if ($user) {
            $personID = getPersonIDFromUsername($user);
//$output .=  "User: $user PersonID: $personID";
            $projects = executeSelect("SELECT * FROM project p, projectpersonnel pp WHERE pp.personID=$personID AND p.projectID=pp.projectID");
        } else {
            $projects = getAllFieldsInTable("project");
        }
//getTwoArgDropDown($projects, "projectDropdown");
        getGenericDropdownMenu($projects, "projectDropdown", NULL, false);
        $output .= '     </td>';
        $output .= ' </tr>';
        $output .= ' <tr class ="fieldLabel"><td>New FY</td>';
        $output .= '     <td class="center">';
        $output .= getDropDownMenu(getFiscalYearArray(), "fyDropdown", NULL, NULL, "getReqTable(this.value)", "fyDropdown");
        $output .= '     </td>';
        $output .= ' </tr>';
        $output .= ' <tr class ="fieldLabel"><td></td>';
        $output .= '     <td class="center" colspan="1">';
        $output .= getFormInputElement("submit", "submit", NULL, "Continue Project");
        $output .= '     </td>';
        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        $output .= getCloseTag("div");
        return $output;
    }

    function processChangeStatus() {
        $projectId = $_POST['projectID'];
        if (isset($_POST['submit'])) {
            $newStatus = getNewStatusFromButtonClick($_POST['submit']);
            if ($newStatus) {
//we need to do some checks here for certain things
//$curStatus = getStatus("project", $projectId);
                if (strcmp($newStatus, "approvalFinal") === 0) {
//If we are moving to finalize Approval
//1. Change all tasks and subtasks that are active --> not started
                    $this->init($projectId, 2);
                    foreach ($this->tasks as $task) {
                        if (!executeUpdate("UPDATE task set status='notStarted' WHERE taskID=$task->ID")) {
                            return NULL;
                        }
                        foreach ($task->subtasks as $subtask) {
                            if (!executeUpdate("UPDATE subtask set status='notStarted' WHERE subtaskID=$subtask->ID")) {
                                return NULL;
                            }
                        }
                    }
                    //Create empty reports for 4 quarters
                    for ($i = 1; $i < 5; $i++) {
                        if (!executeUpdate("INSERT into projectreport (quarter, projectID) values ($i, $projectId) ")) {
                            return NULL;
                        }
                    }
                } else if (strcmp($newStatus, "rebaselineRequest") === 0) {
                    $justification = $_POST['justificationTextfield'];
                    $subtype = "rebaselineRequest";
                    $personId = getPersonIDFromUsername(getCurrentUser());
                    $this->init($projectId, 2);
                    $this->insertNotes($justification, 'project notes', $this->wbsID, $personId, NULL, $subtype, 'active');
                } else if (strcmp($newStatus, "startRebaseline") === 0 || strcmp($newStatus, "viewRebaseline") === 0) {
                    return "location:mainPage.php?request=project&action=viewProjectRebaselinePage&projectId=$projectId";
                }
                if ($this->updateProjectStatusStatic($projectId, $newStatus)) {
                    $activeDiv = 'activeDiv=status';
                    $update = "update=Successfully updated project to $newStatus";
                    return "location:mainPage.php?request=project&action=viewProjectDetails&projectId=$projectId&$update&$activeDiv";
                } else {
                    echo NULL;
                }
            } else {
                echo "no status match <br>";
            }
        } else {
            echo "error no submit detected <br>";
        }
    }

    function getTransitionReportForm() {
        $output = "";
        $output .= getFormLinePost("transitionForm", "mainPage.php?request=project&action=processUploadReportRequest", 'enctype="multipart/form-data"');
        $output .= '<table class="width30">';
        $output .= ' <tr class ="header">';
        $output .= $this->getTD("Transition Plan", NULL, NULL, "width='25%'");
        $output .= ' </tr>';
        foreach ($this->reports as $report) {
            //hack -- if quarter = 0 then this is a transition plan
            if (strcmp($report->quarter, 0) === 0) {
                $output .= ' <tr class="field">';
                if (strcmp($report->status, "submitted") === 0) {
                    $output .= "<td>";
                    if (isPI()) {
                        $output .= "<a href=$report->filepath>$report->filename</a>";
                        $output .= ' ' . getFormInputElement("submit", "submit$report->quarter", NULL, "Delete Plan", "return checkFilename(this)", $report->filepath);
                        $output .= getHiddenField("quarter$report->quarter", $report->quarter);
                        $output .= getHiddenField("filename$report->quarter", $report->filepath);
                        $output .= getHiddenField('projectID', $this->ID);
                    } else {
                        $output .= "<a href=$report->filepath>$report->filename</a>";
                    }
                    $output .= "</td>";
                } else if (isPI()) {
                    $output .= "<td>";
                    $output .= '<input type="file" name="file' . $report->quarter . '" id="file">';
                    $output .= "</td>";
                    $output .= ' <tr class="field">';
                    $output .= "<td>";
                    $output .= getFormInputElement("submit", "submit$report->quarter", NULL, "Upload Plan");
                    $output .= getHiddenField("quarter$report->quarter", $report->quarter);
                    $output .= getHiddenField('projectID', $this->ID);
                    $output .= "</td>";
                } else {
                    $output .= 'Overdue or not yet due';
                }
            }
        }

        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getReportsForm() {
        $output = "";
        $output .= getFormLinePost("transitionForm", "mainPage.php?request=project&action=processUploadReportRequest", 'enctype="multipart/form-data"');
        $output .= '<table class="width100">';
        $output .= ' <tr class ="header">';
        $output .= $this->getTD("Quarter 1", NULL, NULL, "width='25%'");
        $output .= $this->getTD("Quarter 2", NULL, NULL, "width='25%'");
        $output .= $this->getTD("Quarter 3", NULL, NULL, "width='25%'");
        $output .= $this->getTD("Quarter 4", NULL, NULL, "width='25%'");
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        foreach ($this->reports as $report) {
            //hack -- if quarter = 0 then this is a transition plan
            if (strcmp($report->quarter, 0) === 0)
                continue;
            $output .= "<td>";
            if (strcmp($report->status, "submitted") === 0) {
                if (isPI()) {
                    $output .= "<a href=$report->filepath>$report->filename</a>";
                    $output .= ' ' . getFormInputElement("submit", "submit$report->quarter", NULL, "Delete Report", "return checkFilename(this)", $report->filepath);
                    $output .= getHiddenField("quarter$report->quarter", $report->quarter);
                    $output .= getHiddenField("filename$report->quarter", $report->filepath);
                } else {
                    $output .= "<a href=$report->filepath>$report->filename</a>";
                }
            } else if (isPI()) {
//show overdue???                
                $output .= '<input type="file" name="file' . $report->quarter . '" id="file">';
                $output .= getFormInputElement("submit", "submit$report->quarter", NULL, "Upload Report");
                $output .= getHiddenField("quarter$report->quarter", $report->quarter);
            } else {
//either not due or overdue
                $output .= 'Overdue or not yet due';
            }
            $output .= "</td>";
        }
        $output .= getHiddenField('projectID', $this->ID);
        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    /**
     *  Returns the html form Form the given project. The edit button will allow the user to modify
     *  Project details
     * @param type $row mysql result for all fields for a single project.
     */
    function getSingleProjectStatusForm($projectObj) {
        $output = "";
        $output .= getFormLinePost("singleProjectForm", "mainPage.php?request=project&action=processChangeStatusRequest");
//getSingleProjectDetailsTable($row);
        $output .= '<table class="width100">';
        $output .= '<caption>Status</caption>';
        $output .= ' <tr class ="header">';
        $output .= '   <td>Status</td>';
        $output .= '   <td>Proposal Amount ($K)</td>';
        if (isProjectInApprovedState($projectObj->status)) {
            $output .= '   <td>Approved Amount ($K)</td>';
            $output .= '   <td>Difference ($K)</td>';
        }
        $output .= '   <td>Options</td>';
        $output .= ' </tr>';
        $output .= '<tr class="field">';
        $output .= '<td>';
        $output .= getHiddenField("projectID", $projectObj->ID);
        $output .= $projectObj->humanReadableStatus;
        $output .= '</td>';
        $output .= '<td>' . $projectObj->proposedCost . '</td>';
        if (isProjectInApprovedState($projectObj->status)) {
            $output .= '<td>' . $projectObj->approvedCost . '</td>';
            if (($projectObj->approvedCost - $projectObj->proposedCost) < 0) {
                $output .= '<td class="red">' . ($projectObj->approvedCost - $projectObj->proposedCost) . '</td>';
            } else {
                $output .= '<td>' . ($projectObj->approvedCost - $projectObj->proposedCost) . '</td>';
            }
        }
//returns what buttons should be visible depending on project status and user role
        $output .= $this->getProjectStatusOptions($projectObj, "8");
        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    function getRebaselineRequestForm() {
        $output = "";
        $output .= getFormLinePost("singleProjectForm", "mainPage.php?request=project&action=processRebaselineDecision");
        $output .= '<table class="width100">';
        $output .= '<caption>Rebaseline Request</caption>';
        $output .= ' <tr>';
        $output .= ' <td class ="header2">Justification</td>';
        $output .= ' <td class ="header2">Approve/Disapprove</td>';
        $output .= ' <td class ="header2">Comments</td>';
        $output .= ' <td class ="header2">Submit</td>';
        $output .= ' </tr><tr>';
        $note = $this->getNotes('project notes', 'rebaselineRequest', 'active');
        $note = $note[0];
        $output .= ' <td class="field2">' . $note->notes . '</td>';
        $output .= ' <td class="field2">';
        $output .= getFormInputElementText('radio', "group1", "10%", "approve", NULL, "approveRadio", "checked");
        $output .= "Approve<br>";
        $output .= getFormInputElementText('radio', "group1", "10%", "disapprove", NULL, "approveRadio");
        $output .= "Disapprove";
        $output .= ' </td>';
        $output .= ' <td class="field2">';
        $output .= getFormInputElementText("text", "textFieldComments", "98%");
        $output .= ' </td>';
        $output .= ' <td class="field2">';
        $output .= getFormInputElementText("submit", "submit", NULL, "Submit Decision");
        $output .= getHiddenField("projectID", $this->ID);
        $output .= ' </td>';
        $output .= '</tr></table></form>';
        return $output;
    }

    function getProjectStatusOptions($projectObj, $colspan) {
        $output = "";
//echo $this->status;
//if your a pi
        if (strcmp(getUserRole(), "pi") === 0) {
//all tasks have a subtask so a PI may submit if they like
            if (strcmp($projectObj->status, "subtaskSubmit") === 0) {
                $output .= ' <td colspan="' . $colspan . '">';
                $output .= getFormInputElement("submit", "submit", NULL, "Submit Project For Review");
                $output .= ' </td>';
            }
//need tasks and subtasks
            else if (strcmp($projectObj->status, "created") === 0) {
                $output .= ' <td colspan="' . $colspan . '">';
                $output .= 'Please create tasks and subtasks';
                $output .= ' </td>';
            }
//need subtasks
            else if (strcmp($projectObj->status, "taskSubmit") === 0) {
                $output .= ' <td colspan="' . $colspan . '">';
                $output .= 'Please create at least 1 subtask for all task';
                $output .= ' </td>';
            }
//If pi has been asked for feedback then they may re-submit -- Check to see if all feedback is set to complete???
            else if (strcmp($projectObj->status, "piFeedback") === 0) {
                if (doesProjectHaveActiveFeedbackComments($projectObj->ID)) {
                    $output .= ' <td colspan="' . $colspan . '">Not all feedback items are marked as complete</td>';
                } else {
                    $output .= ' <td colspan="' . $colspan . '">';
                    $output .= getFormInputElement("submit", "submit", NULL, "Submit Project For Review");
                    $output .= ' </td>';
                }
            }
//Submit complete PI can do nothing at this point just wait
            else if (strcmp($projectObj->status, "submitComplete") === 0) {
//submitted so no editing or submiting
                $output .= ' <td colspan="' . $colspan . '">Project has been submitted for review</td>';
            }
//Do we wan to show PI this status???
            else if (strcmp($projectObj->status, "piApproverSubmit") === 0) {
//submitted so no editing or submiting
                $output .= ' <td colspan="' . $colspan . '">Project has been submitted for Approval/Disapproval</td>';
            }
//Approved TBD what we can do here
            else if (strcmp($projectObj->status, "approved") === 0) {
//submitted so no editing or submiting
                if (($projectObj->approvedCost - $projectObj->proposedCost) < 0) {
                    $output .= '<td>Please modify tasks/subtasks to equal the approval amount</td>';
                } else {
                    $output .= '<td> ' . getFormInputElementText("submit", "submit", NULL, "Finalize Approval") . '</td>';
                }
            }
//Disapproved :(
            else if (strcmp($projectObj->status, "disapproved") === 0) {
//submitted so no editing or submiting
                $output .= ' <td colspan="' . $colspan . '">Project has been disapproved. See notes.</td>';
            }
//project is actively being worked on (more status' probably to come)
            else if (strcmp($projectObj->status, "approvalFinal") === 0) {
//allow PI to add notes at the project level
                $output .= '<td> ' . getFormInputElementText("submit", "submit", NULL, "Request Rebaseline", "validateRebaselineRequest()");
                $output .= ' <label for="just">Justification</label> ' . getFormInputElementText("text", "justificationTextfield", "50%", NULL, NULL, 'just') . '</td>';
            } else if (strcmp($projectObj->status, "rebaselineDisapproved") === 0) {
                $note = $projectObj->getNotes('project notes', 'rebaselineDecision', 'rebaselineDisapproved');
                $output .= $this->getTD($note->notes . ' ' . getFormInputElementText("submit", "submit", NULL, "Aknowledge"));
            } else if (strcmp($projectObj->status, "rebaselineRequestApproved") === 0) {
                $output .= $this->getTD(getFormInputElementText("submit", "submit", NULL, "Start Rebaseline"));
            } else {
//if not all tasks have a subtask then only edit
                $output .= ' <td colspan="' . $colspan . '">';
//$output .=  'Unknown status';
                $output .= ' </td>';
            }
        }
//if you are a reviewer
        else if (strcmp(getUserRole(), "pireviewer") === 0) {
//Reviewer may now ask for feedback from the PI, or pass on to the approver to approve/disapprove
            if (strcmp($projectObj->status, "submitComplete") == 0) {
                $output .= ' <td colspan="' . $colspan . '">';
                if (doesProjectHaveActiveFeedbackComments($projectObj->ID)) {
                    $output .= getFormInputElement("submit", "submit", NULL, "Submit feedback request to PI");
                }
                $output .= getFormInputElement("submit", "submit", NULL, "Submit to PI Approver", "return myFunction(this.value)");
                $output .= ' </td>';
                $output .= ' </tr>';
            }
//Let's the PI and reviewer know the state
            else if (strcmp($projectObj->status, "piFeedback") == 0) {
//reviewer has requested feedback from pi so no options just wait
                $output .= ' <td colspan="' . $colspan . '">PI has been sent feedback request</td>';
            }
//Let's the reviewer know it is awaiting approver's response
            else if (strcmp($projectObj->status, "piApproverSubmit") == 0) {
//submitted to approver so no options
                $output .= ' <td colspan="' . $colspan . '">PI approver has been sent request to Approve/Disapprove</td>';
            } else if ($this->isStatus("rebaselineSubmitRequest")) {
                $output .= $this->getTD(getFormInputElementText("submit", "submit", NULL, "View Rebaseline Submission"));
            } else {
                $output .= '<td></td>';
            }
        }
//if you are an approver
        else if (strcmp(getUserRole(), "piapprover") === 0) {

//close the form out and make a approve/disapprove form
            $output .= '<td></td></tr>';
            $output .= getCloseTag("table");
            getConfirmBoxScript();
            $output .= getCloseTag("form");
            $output .= '<br><br>';


            if (strcmp($projectObj->status, "piApproverSubmit") == 0) {
//if in approver submit state then show the form elements
                getFormLinePost("singleProjectForm", "editProjectController.php");
                $output .= '<table class="width40Center" cellspacing="1">';
                $output .= '<caption>Project Approve/Disapprove</caption>';
                $output .= ' <tr class ="fieldLabel">';
                $output .= ' <td>';
                $output .= getFormInputElement("submit", "submit", NULL, "Approve", "return myFunction(this.value)");
                $output .= ' </td>';
                $output .= ' <td>Amount</td>';
                $output .= ' <td>';
                $output .= getFormInputElement("text", "textFieldAmountApproved", "30%", $projectObj->approvedCost);
                $output .= ' </td>';
                $output .= ' </tr>';
                $output .= ' <tr class ="fieldLabel">';
                $output .= ' <td>';
                $output .= getFormInputElement("submit", "submit", NULL, "Disapprove", "return myFunction(this.value)");
                $output .= ' </td>';
                $output .= ' <td>Comments</td>';
                $output .= ' <td>';
                $output .= getFormInputElement("text", "textFieldDisapproveComments", "98%");
                $output .= ' </td>';
                getHiddenField("projectID", $projectObj->ID);
                $output .= ' </tr>';
            }
        }
        return $output;
    }

//    function getRebaselineDisapproveComments(){
//        $notesArray = $this->getNotesArray();
//        foreach($notesArray as $note){
//            if(strcmp($note->type, "project notes")===0 && strcmp($note->type, "rebaselineDecision")===0 && )
//        }
//    }
    function getGradingForm($grades) {
        $output = "";
        $gradingSetArray = array();
        $output .= getFormLinePost("gradingForm", "mainPage.php?request=notes&action=processExistingNotes");
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Grading</caption>';
        $output .= ' <col width="15%"><col width="5%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>Category</td>';
        $output .= '     <td title="1=lowest 10=highest">Score</td>';
        $output .= '     <td>Comments</td>';
        $output .= '     <td></td>';
        $output .= ' </tr>';
        $counter = 0;
        $catergoriesSubmitted = array();
        $catergories = getGradingCategoryArray();
        $totalScore = 0;

        //if any categories have been already saved then show them as editable

        foreach ($grades as $grade) {
            $category = $grade->subType;
            $score = $grade->value;
            $comments = $grade->notes;
            $wbsID = $grade->wbsId;
            $personId = $grade->personId;
            array_push($gradingSetArray, $category);
            $output .= '<tr class ="field">';
            $output .= '<td>';
            $output .= $category;
            $output .= getHiddenField("category$counter", $category);
            $output .= '</td>';
            //$output .=  '<td>' . $score . '</td>';
            $output .= '<td>' . getDropDownMenuText(getGradingScoreArray(), " scoreDropdown$counter", $score) . '</td>';
            $totalScore += $score;
            //$output .=  '<td>' . $comments . '</td>';
            $output .= '<td>' . getFormInputElementText('text', "commentsTextField$counter", "98%", $comments) . '</td>';
            //$output .=  '<td>' . getFormInputElementText('submit', "editButton$counter", "98%", "Edit Grade") . '</td>';
            $output .= '<td>' . getFormInputElementText('submit', "button$counter", "98%", 'Save Grade') . '</td>';
            $output .= '</tr>';
            $counter++;
            array_push($catergoriesSubmitted, $category);
        }

        $wbsID = $this->wbsID;
        $personId = getPersonIDFromUsername(getCurrentUser());
        //Whatever categories have not been graded then return a blank form for them to enter data
        for ($i = 0; $i < sizeof($catergories); $i++) {
            //see if this category already is graded
            if (isSringInArray($catergories[$i], $catergoriesSubmitted)) {
                continue;
            }
            $output .= '<tr class ="field">';
            $output .= '<td>';
            $output .= $catergories[$i];
            $output .= getHiddenField("category$counter", $catergories[$i]);
            $output .= '</td>';
            $output .= '<td>' . getDropDownMenuText(getGradingScoreArray(), " scoreDropdown$counter") . '</td>';
            $output .= '<td>' . getFormInputElementText('text', "commentsTextField$counter", "98%") . '</td>';
            $output .= '<td>' . getFormInputElementText('submit', "button$counter", "98%", 'Save Grade') . '</td>';
            $output .= '</tr>';
            $counter++;
        }
        $output .= ' <tr class ="field">';
        $output .= '  <td>Total</td>';
        $output .= '  <td>' . $totalScore . '</td>';
        $output .= '  <td>';
        $output .= getHiddenField("wbsID", $wbsID);
        $output .= getHiddenField("personID", $personId);
        $output .= '    </td>';
        $output .= '  <td></td>';
        $output .= ' </tr>';
        $output .= ' <tr class ="field">';
        $output .= '  <td>Average</td>';
        $output .= '  <td>';
        if (sizeof($catergoriesSubmitted) === 0) {
            $output .= 'N/A';
        } else {
            $output .= round($totalScore / sizeof($catergoriesSubmitted), 2);
        }
        $output .= '</td>';
        $output .= '  <td></td>';
        $output .= '<td>' . getFormInputElementText('submit', "buttonAll", "98%", 'Save All') . '</td>';
        $output .= ' </tr>';
//    $output .=  ' <tr class ="field">';
//    $output .=  ' </tr>';
        $output .= '</table>';
        $output .= '</form>';
        return $output;
    }

    function getProjectFinancialsForm($projectObj) {
        $output = "";
        $output .= getFormLinePostWithOnSubmit("financialsForm", "ProjectController.php", "false");
        $output .= $this->getFinancialsCurrentYearTable($projectObj);
        $output .= '</form>';
        return $output;
    }

    function getProjectForm($type, $fy = NULL, $projectObj = NULL) {
        $output = "";
        if (strcmp($type, "create") === 0) {
            $responsibleOrg = "NRL Reviewer";
            $responsibleOrgAddress = "NRL address??? Use same as performing org?";
            $responsiblePerson = "Dropdown??";
            $responsiblePersonPhone = "XXX-XXX-XXXX";
            $responsiblePersonEmail = "responsiblePerson@email.com";
            $responsiblePersonID = getPersonId($responsiblePerson, $responsiblePersonPhone, $responsiblePersonEmail);
        }

        if (strcmp($type, "create") === 0 || strcmp($type, "edit") === 0) {
            $fy--;
            $startDate = "10/1/$fy";
            $fy++;
            $endDate = "09/30/$fy";
        }

        $output .= $this->getRequiredFieldText();
        $colWidth = 100 / 8;
        if (strcmp($type, "view") === 0) {
            $output .= getFormLinePost("singleProjectForm", "mainPage.php?request=project&action=processExistingProjectRequest&projectId=$projectObj->ID");
        } else {
            $output .= getFormLinePostWithOnSubmit("createProjectForm", "mainPage.php?request=project&action=processNewProposalSubmit", "validate1498(this)");
        }
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%">';
        $output .= '<col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%">';

        $output .= '  <tr width="100%">';
        $output .= '     <td class="form-title" colspan="4" rowspan="2">Research and Technology Research Summary</td>';
        $output .= '     <td class ="header" colspan="2">1. DATE OF SUMMARY</td>';
        $output .= '     <td class ="header" colspan="2">2. DATE PREVIOUS SUMMARY</td>';
        $output .= '  </tr>';
        $output .= ' <tr class="field">';
        $output .= '    <td class="black" colspan="2">';
//        if (strcmp($type, "create") == 0) {
//            $date = date("m/d/Y");
//            $output .= getFormInputElement("text", "textFieldDateOfSummary", NULL, $date, NULL, "datepicker0", "readonly");
//        } else if (strcmp($type, "edit") == 0) {
//            $output .= getFormInputElement("text", "textFieldDateOfSummary", "98%", getDatePickerFormat($projectObj->submitDate), NULL, "datepicker0", "readonly");
//        } else {
//            $output .= $projectObj->submitDate;
//        }
        if (strcmp($type, "view") == 0) {
            $output .= $projectObj->submitDate;
        } else {
            $date = date("m/d/Y");
            $output .= $date;
            $output .= getHiddenField('textFieldDateOfSummary', $date, 'submitDate');
        }
        $output .= '    </td>';
        $output .= '    <td class="black" colspan="2">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldDateOfPrevSummary", NULL, NULL, NULL, "datepicker1");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldDateOfPrevSummary", "98%", getDatePickerFormat($projectObj->prevSummary), NULL, "datepicker1");
        } else {
            $output .= $projectObj->prevSummary;
        }
        $output .= '</td>';
        $output .= '</tr>';

        $output .= ' <tr class ="header">';
        $output .= '     <td class ="header" colspan="2">3. KIND OF SUMMARY</td>';
        $output .= '     <td class ="header" colspan="2">4. SUMMARY SECURITY</td>';
        $output .= '     <td class ="header" colspan="2">5. WORK SECURITY</td>';
        $output .= '     <td class ="header" colspan="2">6. LEVEL OF SUM</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldTypeOfSummary");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldTypeOfSummary", "98%", $projectObj->summaryType);
        } else {
            $output .= $projectObj->summaryType;
        }
        $output .= '    </td>';
        //should only be UNCLASS
        $output .= $this->getTD("UNCLASS" . getHiddenField('textFieldSummarySecurity', "UNCLASS"), "black", NULL, 'colspan="2"');
//        if (strcmp($type, "create") == 0) {
//            //$output .= $this->getTD(getDropDownMenu(getSummarySecurityArray(), 'textFieldSummarySecurity'). ' *', "required", NULL, 'colspan="2"');
//            //$output .= $this->getTD(getFormInputElement("text", "textFieldSummarySecurity", NULL, NULL, NULL, "Summary Security") . ' *', "required", NULL, 'colspan="2"');
//        } else if (strcmp($type, "edit") == 0) {
//            $output .= $this->getTD(getDropDownMenu(getSummarySecurityArray(), 'textFieldSummarySecurity', $projectObj->summarySecurity). ' *', "required", NULL, 'colspan="2"');
//            //$output .= $this->getTD(getFormInputElement("text", "textFieldSummarySecurity", "98%", $projectObj->summarySecurity, NULL, "Summary Security"), "required", NULL, 'colspan="2"');
//        } else {
//            $output .= $this->getTD($projectObj->summarySecurity, "black", NULL, 'colspan="2"');
//        }

        if (strcmp($type, "create") == 0) {
            $output .= $this->getTD('* ' . getDropDownMenu(getWorkSecurityArray(), 'textFieldWorkSecurity'), "required", NULL, 'colspan="2"');
            //$output .= $this->getTD(getFormInputElement("text", "textFieldWorkSecurity", NULL, NULL, NULL, "Work Security") . " *", "required", NULL, 'colspan="2"');
        } else if (strcmp($type, "edit") == 0) {
            $output .= $this->getTD('* ' . getDropDownMenu(getWorkSecurityArray(), 'textFieldWorkSecurity', $projectObj->workSecurity), "required", NULL, 'colspan="2"');
            //$output .= $this->getTD(getFormInputElement("text", "textFieldWorkSecurity", "98%", $projectObj->workSecurity, NULL, "Work Security") . " *", "required", NULL, 'colspan="2"');
        } else {
            $output .= $this->getTD($projectObj->workSecurity, "black", NULL, 'colspan="2"');
        }
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldLevelOfSum");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldLevelOfSum", "98%", $projectObj->levelOfSum);
        } else {
            $output .= $projectObj->levelOfSum;
        }
        $output .= '    </td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="header">';
        $output .= '     <td colspan="2">7. NO/CODES</td>';
        $output .= '     <td class ="header" colspan="2">PROGRAM ELEMENT</td>';
        $output .= '     <td class ="header">PROJECT NUMBER</td>';
        $output .= '     <td class ="header">TASK AREA NUMBER</td>';
        $output .= '     <td class ="header" colspan="2">WORK UNIT NUMBER</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '     <td class="black" colspan="2">a. PRIMARY</td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryProgramElement");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryProgramElement", "98%", $projectObj->priProgramElement);
        } else {
            $output .= $projectObj->priProgramElement;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryProjectNumber");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryProjectNumber", "98%", $projectObj->priProjectNum);
        } else {
            $output .= $projectObj->priProjectNum;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryTaskAreaNumber");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryTaskAreaNumber", "98%", $projectObj->priTaskAreaNum);
        } else {
            $output .= $projectObj->priTaskAreaNum;
        }
        $output .= '    </td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryWorkUnitNumber");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldPrimaryWorkUnitNumber", "98%", $projectObj->priWorkUnitNum);
        } else {
            $output .= $projectObj->priWorkUnitNum;
        }
        $output .= '    </td>';
        $output .= ' </tr>';

        $output .= ' <tr class="field">';
        $output .= '     <td class="black" colspan="2">b. CONTRIBUTING</td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProgramElementB");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProgramElementB", "98%", $projectObj->contrProgramElementB);
        } else {
            $output .= $projectObj->contrProgramElementB;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProjectNumberB");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProjectNumberB", "98%", $projectObj->contrProjectNumB);
        } else {
            $output .= $projectObj->contrProjectNumB;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrTaskAreaNumberB");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrTaskAreaNumberB", "98%", $projectObj->contrTaskAreaNumB);
        } else {
            $output .= $projectObj->contrTaskAreaNumB;
        }
        $output .= '    </td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrWorkUnitNumberB");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrWorkUnitNumberB", "98%", $projectObj->contrWorkUnitNumB);
        } else {
            $output .= $projectObj->contrWorkUnitNumB;
        }
        $output .= '    </td>';
        $output .= ' </tr>';

        $output .= ' <tr class="field">';
        $output .= '     <td class="black" colspan="2">c. CONTRIBUTING</td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProgramElementC");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProgramElementC", "98%", $projectObj->contrProgramElementC);
        } else {
            $output .= $projectObj->contrProgramElementC;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProjectNumberC");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrProjectNumberC", "98%", $projectObj->contrProjectNumC);
        } else {
            $output .= $projectObj->contrProjectNumC;
        }
        $output .= '    </td>';
        $output .= '    <td class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrTaskAreaNumberC");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrTaskAreaNumberC", "98%", $projectObj->contrTaskAreaNumC);
        } else {
            $output .= $projectObj->contrTaskAreaNumC;
        }
        $output .= '    </td>';
        $output .= '    <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldContrWorkUnitNumberC");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldContrWorkUnitNumberC", "98%", $projectObj->contrWorkUnitNumC);
        } else {
            $output .= $projectObj->contrWorkUnitNumC;
        }
        $output .= '    </td>';
        $output .= ' </tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">8. TITLE (Precede with Security Classification Code)</td>';
        $output .= ' </tr>';
        $output .= ' <tr width="100%" class="field">';

        if (strcmp($type, "create") == 0) {
            $output .= $this->getTD("* " . getFormInputElement("text", "textFieldTitle", "98%", NULL, NULL, "Title"), "required", NULL, 'colspan="8"');
        } else if (strcmp($type, "edit") == 0) {
            $output .= $this->getTD("* " . getFormInputElement("text", "textFieldTitle", "97%", $projectObj->title, NULL, "Title"), "required", NULL, 'colspan="8"');
        } else {
            $output .= $this->getTD($projectObj->title, "black", NULL, 'colspan="8"');
        }
        $output .= ' </tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">9. SUBJECT AREAS</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '     <td colspan="8" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldSubjectArea");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldSubjectArea", "98%", $projectObj->subjectArea);
        } else {
            $output .= $projectObj->subjectArea;
        }
        $output .= '     </td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="header">';
        $output .= '     <td colspan="2">10. START DATE</td>';
        $output .= '     <td colspan="2">11. ESTIMATED COMPLETION DATE</td>';
        $output .= '     <td colspan="2">12. FUNDING ORGANIZATION</td>';
        $output .= '     <td colspan="2">13. PERFORMANCE METHOD</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '     <td colspan="2" class="black">';
//        if (strcmp($type, "create") == 0) {
//            $output .= getFormInputElement("text", "textFieldStartDate", NULL, $startDate, NULL, "datepicker2", "readonly");
//        } else if (strcmp($type, "edit") == 0) {
//            $output .= getFormInputElement("text", "textFieldStartDate", "98%", $projectObj->startDate, NULL, "datepicker2", "readonly");
//        }
        if (strcmp($type, "view") == 0) {
            $output .= $projectObj->startDate;
        } else {
            $output .= $startDate;
            $output .= getHiddenField('textFieldStartDate', $date, 'startDate');
        }
        $output .= getHiddenField('fy', $fy);
        $output .= '     </td>';
        $output .= '     <td colspan="2" class="black">';
//        if (strcmp($type, "create") == 0) {
//            $output .= getFormInputElement("text", "textFieldEndDate", NULL, $endDate, NULL, "datepicker3", "readonly");
//        } else if (strcmp($type, "edit") == 0) {
//            $output .= getFormInputElement("text", "textFieldEndDate", "98%", $projectObj->endDate, NULL, "datepicker3", "readonly");
//        } else {
//            $output .= $projectObj->endDate;
//        }
        if (strcmp($type, "view") == 0) {
            $output .= $projectObj->endDate;
        } else {
            $output .= $endDate;
            $output .= getHiddenField('textFieldEndDate', $date, 'endDate');
        }
        $output .= '     </td>';
        $output .= '     <td colspan="2" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldFundingOrg", "98%");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldFundingOrg", "98%", $projectObj->fundingOrg);
        } else {
            $output .= $projectObj->fundingOrg;
        }
        $output .= '     </td>';
        $output .= '     <td class="black" colspan="2">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("text", "textFieldPerformMethod", "98%");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldPerformMethod", "98%", $projectObj->performanceMethod);
        } else {
            $output .= $projectObj->performanceMethod;
        }
        $output .= '     </td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="header">';
        $output .= '     <td colspan="4">14. RESPONSIBLE DOD ORGANIZATION</td>';
        $output .= '     <td colspan="4">15. PERFORMING ORGANIZATION</td>';
        $output .= ' </tr>';
        $output .= ' <tr class ="field">';
//hard code this for now
        $output .= $this->getTD("PEO C4I/PMW 120", NULL, NULL, 'colspan="4"');
//$output .= getFormInputElement('text', 'performingOrgTextField', "98%");
        if (strcmp($type, "view") === 0) {
            $output .= '     <td colspan="4">' . $projectObj->performingOrg . '</td>';
        } else {
            $output .= '<td colspan="4"> Performing Org: ';
            if (strcmp($type, "edit") === 0) {
                $output .= getDropDownMenu(getPerformingOrgs(), 'performingOrgTextField', $projectObj->performingOrg);
//$output .= getFormInputElement('text', 'performingOrgTextField', "98%", "WHAT");
            } else {
                $output .= getDropDownMenu(getPerformingOrgs(), 'performingOrgTextField');
            }
            $output .= '</td>';
        }
        $output .= ' </tr>';
        $output .= ' <tr class ="field">';
//responsible org address
        $output .= $this->getTD("PMW-120, 4301 Pacific Highway OT-01 San Diego, CA 92110-3127", NULL, NULL, 'colspan="4"');
//performing org address
        if (strcmp($type, "view") === 0) {
            $output .= '     <td colspan="4">' . $projectObj->performingOrgAddress . '</td>';
        } else {
            $output .= $this->getTD("", NULL, NULL, 'colspan="4"');
        }
        $output .= ' </tr>';
        $output .= ' <tr class ="header">';
        $output .= $this->getTD("RESPONSIBLE INDIVIDUAL", NULL, NULL, 'colspan="4"');
        $output .= $this->getTD("PRINCIPAL INVESTIGATOR", NULL, NULL, 'colspan="4"');
        $output .= ' </tr>';
        $output .= ' <tr class ="field">';
        $output .= ' <td class="black">Name</td><td class="black">Phone</td><td colspan="2" class="black">Email</td>';
        $output .= ' <td class="black">Name</td><td class="black">Phone</td><td colspan="2" class="black">Email</td>';
        $output .= ' </tr>';
        $output .= ' <tr class ="field">';
        $output .= '     <td>Mr. Diallo Wallace</td>';
        $output .= '     <td>619-524-7932</td>';
        $output .= '     <td colspan="2">diallo.wallace@navy.mil</td>';

        if (strcmp($type, "create") == 0) {
            $pi = new projectPersonnel(NULL, getCurrentUser());
        }
        //pi
        if (strcmp($type, "create") == 0) {
            //$output .= $this->getTD('<span style="color:#bb0000">* </span>' . $pi->name . getHiddenField('piNameTextField', $pi->name));
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piNameTextField', "90%", $pi->name, NULL, "PI Name"));
        } else if (strcmp($type, "edit") == 0) {
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piNameTextField', "90%", $projectObj->getPI()->name, NULL, "PI Name"), "required");
        } else {
            $output .= $this->getTD($projectObj->getPI()->name);
        }
        if (strcmp($type, "create") == 0) {
            //$output .= $this->getTD('<span style="color:#bb0000">* </span>' . $pi->phone . getHiddenField('piPhoneTextField', $pi->phone));
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piPhoneTextField', "90%", $pi->phone, NULL, "PI Phone"));
        } else if (strcmp($type, "edit") == 0) {
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piPhoneTextField', "90%", $projectObj->getPI()->phone, NULL, "PI Phone"), "required");
        } else {
            $output .= $this->getTD($projectObj->getPI()->phone);
        }
//$output .= '     <td class="form-title" colspan="2" id="aiEmailBox">';
        if (strcmp($type, "create") == 0) {
            //$output .= $this->getTD('<span style="color:#bb0000">* </span>' . $pi->email . getHiddenField('piEmailTextField', $pi->email), NULL, NULL, 'colspan="2"');
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piEmailTextField', "90%", $pi->email, NULL, "PI Email"), NULL, NULL, 'colspan="2"');
        } else if (strcmp($type, "edit") == 0) {
            $output .= $this->getTD('<span style="color:#bb0000">* </span>' . getFormInputElement('text', 'piEmailTextField', "90%", $projectObj->getPI()->email, NULL, "PI Email"), "required", NULL, 'colspan="2"');
        } else {
            $output .= $this->getTD($projectObj->getPI()->email, NULL, NULL, 'colspan="2"');
        }
//$output .= '</td>';
        $output .= ' <tr>';

//ASSOCIATE INVESTIGATORS
        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="4">16. GENERAL USE</td>';
        $output .= '     <td colspan="4">17. ASSOCIATE INVESTIGATOR(S)</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= ' <td class="black">APPLICATION</td>';
        $output .= '     <td colspan="3" class="black">';
        $array = array("MILITARY", "CIVILIAN");
        if (strcmp($type, "create") == 0) {
            $output .= getDropDownMenu($array, "appDropdown");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getDropDownWithSelection($array, "appDropdown", $projectObj->application);
        } else {
            $output .= $projectObj->application;
        }
        if (strcmp($type, "view") !== 0) {
            $output .= ' <td class="black">Name</td><td class="black">Phone</td><td colspan="2" class="black">Email</td>';
        } else {
            $output .= ' <td colspan="4"></td>';
        }
        $output .= '</tr>';

//show empty textfields to add ais
        if (strcmp($type, "edit") === 0 || strcmp($type, "create") === 0) {
            $output .= '<tr>';
            $output .= '     <td colspan="4" class="field"></td>';
            $output .= '     <td class="field">';
            $output .= getFormInputElement("text", "textFieldAiName", "97%", NULL, NULL, "aiName");
            $output .= '     </td>';
            $output .= '     <td class="field">';
            $output .= getFormInputElement("text", "textFieldAiPhone", "97%", NULL, NULL, "aiPhone");
            $output .= '     </td>';
            $output .= '     <td class="field">';
            $output .= getFormInputElement("text", "textFieldAiEmail", "97%", NULL, NULL, "aiEmail");
            $output .= '     </td>';
            $output .= '     <td class="field">';
            $output .= getFormInputElement("button", "addButton", NULL, 'Add', "addAiRow()", NULL);
            $output .= '     </td>';
            $output .= ' </tr>';
        }


        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="4" class="field"></td>';
        $output .= '     <td class="field" colspan="4">';
        $output .= '       <table class="width100" cellspacing="1" id="aiTable">';
//$output .=  '       <col width="20%"><col width="20%"><col width="30%"><col width="10%">';
        $output .= '        <tr class ="header">';
        $output .= '          <td>Name</td>';
        $output .= '          <td>Phone</td>';
        $output .= '          <td>Email</td>';
        $output .= '          <td></td>';
        $output .= '        </tr>';

//if edit or view show the existing ais associated with this project
        if (strcmp($type, "edit") === 0 || strcmp($type, "view") === 0) {
            $aiList = $this->getAiList();
            for ($i = 0; $i < sizeof($aiList); $i++) {
                $output .= '        <tr id="row' . $i . '" class="field">';
                $output .= '     <td class="black">';
                $output .= '       <input type="hidden" id="nameField' . $i . '" name="nameField' . $i . '" value="' . $aiList[$i]->name . '">' . $aiList[$i]->name . '';
                $output .= '     </td>';
                $output .= '     <td class="black">';
                $output .= '       <input type="hidden" id="phoneField' . $i . '" name="phoneField' . $i . '" value="' . $aiList[$i]->phone . '">' . $aiList[$i]->phone . '';
                $output .= '     </td>';
                $output .= '     <td class="black">';
                $output .= '       <input type="hidden" id="emailField' . $i . '" name="emailField' . $i . '" value="' . $aiList[$i]->email . '">' . $aiList[$i]->email . '';
                $output .= '     </td>';
                $output .= '     <td class="field">';
                if (strcmp($type, "edit") == 0) {
                    $output .= getFormInputElement("button", "$i", NULL, 'Remove', "removeAiRow(this.name)", NULL);
                }
                $output .= '</td>';
                $output .= '        </tr>';
            }
        }
//$output .=  '        </tr>';
        $output .= getCloseTag("table");
        $output .= '     </td>';
//$output .=  '     <td class="field"></td>';
        $output .= ' </tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">18. TECHNICAL OBJECTIVE (2500 characters max)</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '     <td colspan="8" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getTextArea("technicalObjectiveTextArea", 2500, NULL, 320);
        } else if (strcmp($type, "view") == 0) {
            $output .= getTextArea("technicalObjectiveTextArea", 2500, $projectObj->technicalObjective, 320, 'disabled class="ReadOnly"');
        } else {
            $output .= getTextArea("technicalObjectiveTextArea", 2500, $projectObj->technicalObjective, 320);
        }
        $output .= '     </td>';
        $output .= ' </tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">19. APPROACH (2500 characters max)</td>';
        $output .= ' </tr>';
        $output .= '     <td colspan="8" class="black">';
        if (strcmp($type, "create") == 0) {
            $output .= getTextArea("approachTextArea", 2500, NULL, 320);
        } else if (strcmp($type, "edit") == 0) {
            $output .= getTextArea("approachTextArea", 2500, $projectObj->approach, 320);
        } else {
            $output .= getTextArea("approachTextArea", 2500, $projectObj->approach, 320, 'disabled class="ReadOnly"');
        }
        $output .= '     </td></tr>';
        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">20. PROGRESS (Previous FY if applicable - 2500 characters max)</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="field">';
        $output .= '     <td colspan="8" class="black">';
        if (strcmp($type, "edit") == 0) {
            $output .= getTextArea("progressTextArea", 2500, $projectObj->progress, 320);
        } else if (strcmp($type, "create") == 0) {
            $output .= getTextArea("progressTextArea", 2500, NULL, 320);
        } else {
            $output .= getTextArea("progressTextArea", 2500, $projectObj->progress, 320, 'disabled class="ReadOnly"');
        }
        $output .= '     </td></tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td colspan="8">21. BACKGROUND (2500 characters max)</td>';
        $output .= ' </tr>';
        $output .= '     <td colspan="8" class="black">';
        if (strcmp($type, "edit") == 0) {
            $output .= getTextArea("backgroundTextArea", 2500, $projectObj->background, 320);
        } else if (strcmp($type, "create") == 0) {
            $output .= getTextArea("backgroundTextArea", 2500, NULL, 320);
        } else {
            $output .= getTextArea("backgroundTextArea", 2500, $projectObj->background, 320, 'disabled class="ReadOnly"');
        }
        $output .= '     </td>';
        $output .= ' </tr>';

//Leave in for testing. This should be created when the project is approved?
//        $output .= '<tr><td colspan="8">Should WBS be entered by PI??? For entering pilot 1498 projects the following fields are available</td></tr>';
//        if ($projectObj) {
//            $output .= $this->getWbsRow($type, $this->wbsID);
//        } else {
//            $output .= $this->getWbsRow($type);
//        }
//submit/edit button
        if ($projectObj) {
            $output .= $this->getProjectButtonOptions($type, $projectObj->ID);
        } else {
            $output .= $this->getProjectButtonOptions($type);
        }
        $output .= '</table>';
        $output .= '</form>';
        return $output;
    }

    /**
     * 
     * @param type $type
     * @param type $wbsId
     */
    function getWbsRow($type, $wbsId = NULL) {
        $output = "";
//WBS stuff
        $output .= ' <tr width="100%" class ="header">';
        $output .= '     <td>22. WBS ID</td>';
        $output .= '     <td colspan="4">23. WBS DESCRIPTION</td>';
//echo '     <td colspan="2">WBS PARAMETER</td>';
        $output .= '     <td colspan="4">24. WBS OTHER</td>';
        $output .= ' </tr>';
        $output .= ' <tr width="100%" class ="field">';
        $output .= '     <td class="black">';

        if (strcmp($type, "edit") == 0 || strcmp($type, "view") == 0) {
            $wbsQuery = "SELECT * FROM wbs WHERE wbsId=$wbsId";
            $wbsResult = executeSelect($wbsQuery);
            $wbsRow = mysqli_fetch_array($wbsResult);
            $wbsDesc = $wbsRow['description'];
            $wbsOther = $wbsRow['other'];
            $wbsString = $wbsRow['wbsString'];
            if (strcmp($type, "view") == 0) {
                $output .= $wbsString;
            } else {
                $output .= getFormInputElement("text", "textFieldWbsID", "98%", $wbsString);
            }
        } else {
            $output .= getFormInputElement("text", "textFieldWbsID", "98%");
        }
        $output .= '     </td>';

        $output .= '     <td class="black" colspan="4">';
        if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldWbsDescription", "98%", $wbsDesc);
        } else if (strcmp($type, "view") == 0) {
            $output .= $wbsDesc;
        } else {
            $output .= getFormInputElement("text", "textFieldWbsDescription", "98%");
        }
        $output .= '     </td>';
        $output .= '     <td class="black" colspan="4">';
        if (strcmp($type, "edit") == 0) {
            $output .= getFormInputElement("text", "textFieldWbsOther", "98%", $wbsOther);
        } else if (strcmp($type, "view") == 0) {
            $output .= $wbsOther;
        } else {
            $output .= getFormInputElement("text", "textFieldWbsOther", "98%");
        }
        $output .= '     </td>';
        $output .= ' </tr>';

        $output .= ' <tr width="100%" class ="header">';
        $output .= ' </tr>';
        return $output;
    }

    function getProjectButtonOptions($type, $projectID = NULL) {
        $output = "";
        $output .= ' <tr width="100%" class ="fieldLabel">';
        $output .= '     <td colspan="3">';
        $output .= '    </td>';
        $output .= '     <td colspan="2">';
        if (strcmp($type, "create") == 0) {
            $output .= getFormInputElement("submit", "submit", "100%", "Continue");
        } else if (strcmp($type, "edit") == 0) {
            $output .= getHiddenField("projectID", $projectID);
            $output .= getFormInputElement("submit", "submit", "100%", "Submit Changes");
        } else {
//only a PI is allowed to modify a project
            if (strcmp(getUserRole(), "pi") === 0) {
//                if (strcmp(getStatus("project", $projectID), "taskSubmit") === 0 || strcmp(getStatus("project", $projectID), "subtaskSubmit") === 0 ||
//                        strcmp(getStatus("project", $projectID), "piFeedback") === 0 || strcmp(getStatus("project", $projectID), "created") === 0) {
                if (!isProjectInApprovedState($this->status)) {
                    $output .= getFormInputElement("submit", "submit", "100%", "Edit Project");
                }
            }
            $output .= getHiddenField("projectID", $projectID);
        }
        $output .= '    </td>';
        $output .= '     <td colspan="3">';
        $output .= '    </td>';
        $output .= ' </tr>';

//feedback
        if (strcmp(getUserRole(), "pireviewer") === 0) {
            if (strcmp(getStatus("project", $projectID), "submitComplete") === 0) {
                $output .= '<tr class ="fieldLabel">';
                $output .= ' <td>';
                $output .= getHiddenField("wbsID", $this->wbsID);
                $output .= getFormInputElement("submit", "submit", NULL, "Add Notes");
                $output .= ' </td>';
                $output .= ' <td>' . getDropDownMenuText(getNotesTypeArray(), "notesTypeDropdown") . '</td>';
                $output .= ' <td colspan="7">';
                $output .= getFormInputElement("text", "textFieldNotes", "99%");
                $output .= ' </td>';
                $output .= '</tr>';
            }
        }
        return $output;
    }

//TABLES************************************************************************

    function getContractSummaryTable($projectObj, $showLink = NULL) {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Contracts</caption>';
        $output .= ' <col width="16%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>Contract Number</td>';
        $output .= '     <td>COR</td>';
        $output .= '     <td>Email</td>';
        $output .= '     <td>Phone</td>';
        $output .= '     <td>POP Start</td>';
        $output .= '     <td>POP End</td>';
        $output .= '     <td>Amount</td>';
        $output .= ' </tr>';
        foreach ($projectObj->contracts as $contract) {
            $output .= ' <tr class="field">';
            if (!$showLink) {
                $output .= "<td>$contract->contractNumber</td>";
            } else {
                $output .= ' <td><a class="black" href="mainPage.php?request=project&action=viewContractDetails&projectId=' . $projectObj->ID . '&contractId=' . $contract->contractID . '">' . $contract->contractNumber . '</a></td>';
            }
            $output .= ' <td>' . $contract->name . '</td>';
            $output .= ' <td>' . $contract->email . '</td>';
            $output .= ' <td>' . $contract->phone . '</td>';
            $output .= ' <td>' . $contract->startDate . '</td>';
            $output .= ' <td>' . $contract->endDate . '</td>';
            $output .= ' <td>' . $contract->amount . '</td>';
            $output .= ' </tr>';
            $output .= getHiddenField("contractNumber", $contract->contractNumber);
        }
        return $output;
    }

    function getNonLaborSummaryTable($projectObj, $showLink) {
        $output = "";
        $output .= '<table class="width50" cellspacing="1">';
        $output .= '<caption>Non Labor Expenses</caption>';
        $output .= ' <col width="65%">';
        $output .= ' <tr class="header">';
        $output .= '     <td>Type</td>';
        $output .= '     <td>Proposed Cost ($K)</td>';
        $output .= '     </tr>';
//there should only be be 2 these will be created when a initial proposal (1498 form) is submitted
        foreach ($projectObj->nonLaborExpenses as $nonLabor) {
            $output .= ' <tr class="field">';
            $output .= ' <td>' . $nonLabor->type . ' ' . getHiddenField("type", $nonLabor->type) . '</td>';
            if (isPI() && (!isProjectInApprovedState($projectObj->status) || strcmp($projectObj->status, 'approved') === 0)) {
                //echo $nonLabor->proposedCost.'<br>';
                if (strcmp($nonLabor->proposedCost, "-1") === 0) {
                    $output .= '     <td>' . getFormInputElement("text", $nonLabor->type . 'CostTextfield', '96%') . '</td>';
                } else {
                    $output .= '     <td>' . getFormInputElement("text", $nonLabor->type . 'CostTextfield', '96%', $nonLabor->proposedCost) . '</td>';
                }
            } else {
                $output .= ' <td>' . $nonLabor->proposedCost . '</td>';
            }
            $output .= getHiddenField($nonLabor->type . "nonLaborId", $nonLabor->nonLaborID);
            $output .= '</tr>';
        }
        if (isPI() && (!isProjectInApprovedState($projectObj->status) || strcmp($projectObj->status, 'approved') === 0)) {
            $output .= '<tr class ="fieldLabel">';
            $output .= ' <td colspan="2">' . getFormInputElement("submit", "submit", NULL, "Save Expense") . '</td>';
            $output .= '</tr>';
        }
        return $output;
    }

    /**
     * Gets the html table of the tasks contained in the given result resource.
     * @param type $result the result resource related to a unique edrID from the db (contains 1 or more rows)
     */
    function getTaskSummaryTable($projectObj) {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Tasks</caption>';
        $output .= ' <col width="6%">';
        $output .= ' <tr class="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td><Title</td>';
        $output .= '     <td>Description</td>';
        $output .= '     <td>Start Date</td>';
        $output .= '     <td>End Date</td>';
        $output .= '     <td>Duration</td>';
        $output .= '     <td>Cost</td>';
        $output .= '     <td>Status</td>';
        $output .= ' </tr>';
        foreach ($projectObj->tasks as $task) {

            $statusBGcolor = getStatusBackgroundColor($task->status, 'task');
            $output .= ' <tr class="field">';
            $output .= ' <td><a class="black" href="mainPage.php?request=task&projectId=' . $projectObj->ID . '&taskId=' . $task->ID . '&action=viewTaskDetails">' . $task->wbsString . '</a></td>';
            $output .= ' <td>' . $task->title . '</td>';
            $output .= ' <td>' . $task->description . '</td>';
            $output .= ' <td>' . $task->startDate . '</td>';
            $output .= ' <td>' . $task->endDate . '</td>';
            $output .= ' <td>' . $task->duration . '</td>';
            $output .= ' <td>' . $task->proposedCost . '</td>';
            if (strcmp($task->status, "subtaskRequired") === 0) {
                $output .= ' <td bgcolor="#FF0000">' . getStatusHumanReadableString("subtaskRequired", "task") . '</td>';
            } else {
                $output .= " <td bgcolor = \"$statusBGcolor\">$task->status</td>";
            }
            $output .= '</tr>';
        }
        return $output;
    }

    function getNonLaborFinancialTable() {
        $totalMaterialsProposed = 0;
        $totalMaterialsActual = 0;
        $totalTravelProposed = 0;
        $totalTravelActual = 0;

        $output = "";
        if (isPI()) {
//nonlabor table
            $output .= '<table class="width30" cellspacing="1">';
            $output .= '<col width="30%">';
            $output .= '<tr class="header"><td>Description</td><td>Proposed $(K) Total</td><td>Actual $(K)</td></tr>';
            $count = 0;
            foreach ($this->nonLaborExpenses as $expense) {
                $output .= '<tr>';
                if (strcmp($expense->type, "Materials and Equipment") === 0) {
                    $output .= $this->getTD($expense->description);
                    $output .= $this->getTD($expense->proposedCost);
                    $output .= $this->getTD("<input type='button$count' onclick=\"updateNonLaborFinancial(this)\" name='materials$count' id='materials$count' value='$expense->actualCost'></input>");
                    $totalMaterialsProposed += $expense->proposedCost;
                    $totalMaterialsActual += $expense->actualCost;
                } else {
                    $output .= $this->getTD($expense->description);
                    $output .= $this->getTD($expense->proposedCost);
                    $totalTravelProposed += $expense->proposedCost;
                    $totalTravelActual += $expense->actualCost;
                }
                $output .= '<tr>';
                $count++;
            }
            $output .= '</table>';
        } else {
            foreach ($this->nonLaborExpenses as $expense) {
                if (strcmp($expense->type, "Materials and Equipment") === 0) {
                    $totalMaterialsProposed += $expense->proposedCost;
                    $totalMaterialsActual += $expense->actualCost;
                } else {
                    $totalTravelProposed += $expense->proposedCost;
                    $totalTravelActual += $expense->actualCost;
                }
            }
        }
//Totals table
        $output .= '<table class="width30" cellspacing="1">';
        $output .= '<col width="30%">';
        $output .= '<tr class="header"><td></td><td>CY Planned Total</td><td>CY Actual Total</td></tr>';

//Materials Total
        $output .= '<tr><td>Materials</td><td>' . financialClass::myRound($totalMaterialsProposed) . '</td>';
        $output .= '<td>' . financialClass::myRound($totalMaterialsActual) . '</td></tr>';
//Travel Total
        $output .= '<tr><td>Travel</td><td>' . financialClass::myRound($totalTravelProposed) . '</td>';
        $output .= '<td>' . financialClass::myRound($totalTravelActual) . '</td></tr>';

        $output .= '</table>';
        return $output;
    }

    function getRebaselineProposedForm() {
        $output = "<br>";
        $output .= getFormLinePost('rebaselineProposalForm', "mainPage.php?request=project&action=processRebaselineSubmit&projectId=$this->ID");
        $output .= $this->getFinancialsCurrentYearTable($this);

//        $output .= '<table class="width100" cellspacing="1">';
//        $output .= '<tr class="header"><td colspan="4" rowspan="2">Subtask</td><td colspan="4">Hour</td><td colspan="4">Cost</td></tr>';
//        $output .= '<tr class="header"><td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td><td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td></tr>';
//        
//        $output .= '<tr><td colspan="4">Original Proposed</td></tr>';
//        //loop
//        $output .= '<tr><td colspan="2">Requested Proposed</td></tr>';
//        foreach ($this->tasks as $task) {
//            foreach ($task->subtasks as $subtask) {
//                //if(strcmp($subtask->financialObject->valuePropo))
//            }
//        }
//        $output .= "</table></form>";
        $output .= "</form>";
        return $output;
    }

    function getFinancialsCurrentYearTable($projectObj) {
//frog
        $financialTotals = new financialTotals();
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
//$output .= '<col width="7%"><col width="7%"><col width="7%"><col width="7%">';
//$output .= '<col width="15%"><col width="15%"><col width="5%"><col width="4%"><col width="4%">';
        $output .= '<caption>Financials</caption>';
        $output .= commonModel::getFinancialTableHeader();

        foreach ($projectObj->tasks as $task) {
            $output .= ' <tr>';
            $output .= '  <td></td>';
            $output .= ' </tr>';
            $output .= ' <tr>';
            $bgColor = getStatusBackgroundColor($task->status, "task");
            $output .= '  <td bgcolor="' . $bgColor . '" colspan="21" class="taskTitleWhiteText">';
            $output .= '<b><a class="white" href="mainPage.php?request=task&action=viewTaskDetails&taskId=' . $task->ID . '&projectId=' . $this->ID . '">';
            $output .= $task->wbsString . ' -- ' . $task->title . '</a></b></td>';
            $output .= ' </tr>';
            $output .= ' <tr>';
            $output .= '  <td></td>';
            $output .= ' </tr>';
            foreach ($task->subtasks as $subtask) {
                $output .= ' <tr>';
                $bgColor = getStatusBackgroundColor($subtask->status, "task");
                $output .= $this->getTD("$subtask->percentComplete %", NULL, NULL, "rowspan='2'");
                $output .= " <td bgcolor='$bgColor' class='border1' colspan='2' rowspan='2'>";
                $output .= "<a class=\"white\" href=\"mainPage.php?request=subtask&action=viewSubtaskDetails&subtaskId=$subtask->ID\">";
                $output .= "$subtask->wbsString -- $subtask->title</a>";
                $output .= "</td><td>-</td><td>-</td>";
                $actualCost = $subtask->financialObject->actualDollars;
                $actualHours = $subtask->financialObject->actualDuration;
                $proposedCost = $subtask->financialObject->curYearDollars;
                $proposedHours = $subtask->financialObject->curYearDuration;
                if ($this->isStatus("rebaselineSubmitRequest")) {
                    $proposedRebaselineCost = $subtask->financialObject->rebaselineDollars;
//echo "rb cost: " . $subtask->financialObject->rebaselineDollars[0];
                    $proposedRebaselineHours = $subtask->financialObject->rebaselineDuration;
                }
                $output .= "  <td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td><td class='border1'>P</td>";
//proposed hours
                for ($i = 0; $i < 4; $i++) {
                    $value = $proposedHours[$i];
                    $output .= '<td width="3%">';
                    $name = "$this->ID,$task->ID,$subtask->ID,hours,$i";
//if this is a pi and they are allowed to rebaseline then show textfields
                    if (strcmp($this->status, "rebaselineRequestApproved") === 0 && isPI()) {
                        $output .= getFormInputElement('text', $name, "90%", $value, NULL);
//$output .= getHiddenField("subtaskHours$i", $this->ID);
                        $output .= '  </td>';
                    } else if ($this->isStatus("rebaselineSubmitRequest")) {
//$output .= "  <td class='border1'>";
                        $output .= getHiddenField($name, $proposedRebaselineHours[$i]);
                        $output .= $proposedRebaselineHours[$i] . "</td>";
                    }
                    else
                        $output .= $proposedHours[$i] . "</td>";

                    $financialTotals->proposedHourTotal[$i] += $proposedHours[$i];
                }
//proposed dollars
                for ($i = 0; $i < 4; $i++) {
                    $value = $proposedCost[$i];
                    $output .= '<td width="3%">';
                    $name = "$this->ID,$task->ID,$subtask->ID,cost,$i";
                    if (strcmp($this->status, "rebaselineRequestApproved") === 0 && isPI()) {
                        $output .= getFormInputElement('text', $name, "90%", $value, NULL);
                        $output .= '  </td>';
                    } else if ($this->isStatus("rebaselineSubmitRequest")) {
//$output .= "  <td class='border1'>$proposedRebaselineCost[$i]</td>";
                        $output .= getHiddenField($name, $proposedRebaselineCost[$i]);
                        $output .= $proposedRebaselineCost[$i] . "</td>";
                    }
                    else
                        $output .= $proposedCost[$i] . "</td>";

                    $financialTotals->proposedDollarTotal[$i] +=$proposedCost[$i];
                }
                $output .= "<td class=\"blackBack\"></td><td class=\"blackBack\"></td>";
                $output .= ' </tr>';
                $output .= ' <tr class="grey">';
                $output .= '  <td>-</td><td>-</td>';
                $output .= '  <td>-</td><td>-</td><td>-</td><td>-</td><td>A</td>';
//actual hours
                for ($i = 0; $i < 4; $i++) {
                    $value = $actualHours[$i];
                    $name = $subtask->projectID . ',' . $subtask->taskID . ',' . $subtask->ID . ',hours,' . $i;
                    $quarter = $i + 1;
//$output .= "<td>";
//if (isPI()) {
//                        $output .= " <input type='button' onclick=\"updateTaskFinancial(this)\" name='$name' id='hours$subtask->ID$i' value='$value'></input>";
//$output .= " <input type='text' name='$name' id='hours$subtask->ID$i'></input>";
//    $output .= $this->getTD(getFormInputElement("text", "$name", '20px', NULL, NULL, NULL, NULL, "New Quarter $quarter proposed hours"));
//$output .= $this->getTD();
// } else {
                    $output .= $this->getTD($value);
//}
//$output .= "</td>";
                    $financialTotals->actualHourTotal[$i] += $actualHours[$i];
                }
//actual dollars
                for ($i = 0; $i < 4; $i++) {
                    $value = $actualCost[$i];
                    $name = $subtask->projectID . ',' . $subtask->taskID . ',' . $subtask->ID . ',cost,' . $i;
//$output .= "<td><div onclick=\"myFunction2(this)\" name='$name' id='cost$i' value='$value'>";
//$output .= "<td>";
//                    if (isPI()) {
//                        $output .= $this->getTD(getFormInputElement("text", "$name", '20px', NULL, NULL, NULL, NULL, "New Quarter $quarter proposed cost"));
////                        $output .= "<input type='button' onclick=\"updateTaskFinancial(this)\" name='$name' id='cost$subtask->ID$i' value='$value'></input>";
//                    } else {
                    $output .= $this->getTD($value);
//}
//$output .= "</td>";
                    $financialTotals->actualDollarTotal[$i] += $actualCost[$i];
                }
                $output .= "<td>-</td><td>-</td>";
                $output .= ' </tr>';
            }
        }

        if (!$projectObj->isStatus("rebaselineRequestApproved") && !$projectObj->isStatus("rebaselineSubmitRequest")) {
            $output .= $this->getFinancialTotals($financialTotals);
        }
//        else if (isPI() && $projectObj->isStatus("rebaselineRequestApproved")) {
//            $output .= '<tr class ="fieldLabel">';
//            $output .= $this->getTD(getFormInputElement('submit', 'submit', NULL, "Submit New Proposed Values"), NULL, NULL, 'colspan="20"') . '</tr>';
//        }

        $output .= ' </table>';
        return $output;
    }

    protected function getFinancialTotals($financialTotals) {
        $output = "";
//totals
        $output .= '<tr class="blue">';
        $output .= '<td colspan="9" rowspan="2">Labor Cost Totals (Quarterly)</td>';
        $output .= '<td class="border1">P</td>';
        for ($i = 0; $i < 4; $i++) {
            $output .= '  <td>' . $financialTotals->proposedHourTotal[$i] . '</td>';
        }
        for ($i = 0; $i < 4; $i++) {
            $output .= '  <td>' . $financialTotals->proposedDollarTotal[$i] . '</td>';
        }
        $output .= "<td colspan=\"2\" rowspan='2'></td>";
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= '<td class="border1">A</td>';

        for ($i = 0; $i < 4; $i++) {
            $value = $financialTotals->actualHourTotal[$i];
            $id = "totalHour$i";
            $output .= '  <td id="' . $id . '">';
            $output .= $financialTotals->actualHourTotal[$i];
            $output .= "</td>";
        }
        for ($i = 0; $i < 4; $i++) {
            $id = "totalCost$i";
            $output .= '  <td id="' . $id . '">' . $financialTotals->actualDollarTotal[$i] . '</td>';
        }
//Yearly totals
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= '<td colspan="9" rowspan="2">Labor Cost Totals (Year)</td>';
        $output .= "<td>P</td>";
        $output .= '<td colspan="4">' . $financialTotals->getProposedYearTotal("hour") . '</td>';
        $output .= '<td colspan="4">' . $financialTotals->getProposedYearTotal("cost") . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= "<td>A</td>";
        $output .= '<td colspan="4">' . $financialTotals->getActualYearTotal("hour") . '</td>';
        $output .= '<td colspan="4">' . $financialTotals->getActualYearTotal("cost") . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
//MATERIALS
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= '<td colspan="9" rowspan="2">Material and Equipment Cost Totals</td>';
        $output .= "<td>P</td>";
        $output .= "<td colspan='4'>-</td>";
        $output .= '<td colspan="4">' . $this->getNonlaborExpense('Materials and Equipment')->proposedCost . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= "<td>A</td>";
        $output .= "<td colspan='4'>-</td>";
        $output .= '<td colspan="4">' . $this->getNonlaborExpense('Materials and Equipment')->actualCost . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
//TRAVEL
        $output .= '<tr class="blue">';
        $output .= '<td colspan="9" rowspan="2">Travel and Per Diem Cost Totals</td>';
        $output .= "<td>P</td>";
        $output .= "<td colspan='4'>-</td>";
        $output .= '<td colspan="4">' . $this->getNonlaborExpense('Travel and Per Diem')->proposedCost . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
        $output .= '<tr class="blue">';
        $output .= "<td>A</td>";
        $output .= "<td colspan='4'>-</td>";
        $output .= '<td colspan="4">' . $this->getNonlaborExpense('Travel and Per Diem')->actualCost . '</td>';
        $output .= "<td colspan='4'></td>";
        $output .= '</tr>';
        return $output;
    }

    protected function addUpArray($array) {
        $output = 0;
        for ($i = 0; $i < sizeof($array); $i++)
            $output += $array[$i];
        return $output;
    }

    function getFinancialsSingleTable() {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<col width="20%">';
        $output .= '<caption>Financials</caption>';
        $output .= ' <tr class ="header">';
        $output .= '  <td colspan="3">Last Updated: db</td>';
        $output .= '  <td colspan="12">Current Year Planned</td>';
        $output .= '  <td colspan="8">Current Year Actuals</td>';
        $output .= '  <td colspan="2">Inception to Date</td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="header">';
        $output .= '  <td></td>';
        $output .= '  <td colspan="2">Previous Year</td>';
        $output .= '  <td colspan="4">Milestones</td>';
        $output .= '  <td colspan="4">Hours</td>';
        $output .= '  <td colspan="4">Dollars ($K)</td>';
        $output .= '  <td colspan="4">Hours</td>';
        $output .= '  <td colspan="4">Dollars ($K)</td>';
        $output .= '  <td colspan="2">PY(s) + CY Actuals</td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="header">';
        $output .= '  <td>Task</td>';
        $output .= '  <td>Hours</td>';
        $output .= '  <td>Dollars ($K)</td>';
        $output .= '  <td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td>';
        $output .= '  <td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td>';
        $output .= '  <td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td>';
        $output .= '  <td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td>';
        $output .= '  <td>Q1</td><td>Q2</td><td>Q3</td><td>Q4</td>';
        $output .= '  <td>Hours</td>';
        $output .= '  <td>Dollars ($K)</td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="field">';
        $output .= '  <td>A descent sized task Name</td>';
        $output .= '  <td>56</td>';
        $output .= '  <td>23</td>';
        $output .= '  <td>C</td><td>T</td><td>D</td><td>R</td>';
        $output .= '  <td>12</td><td>22</td><td>9</td><td>20</td>';
        $output .= '  <td>8</td><td>15</td><td>20</td><td>11</td>';
        $output .= '  <td>7</td><td>15</td><td>18</td><td>10</td>';
        $output .= '  <td>11</td><td>17</td><td>22</td><td>13</td>';
        $output .= '  <td>80</td>';
        $output .= '  <td>170</td>';
        $output .= ' </tr>';
        return $output;
    }

    function getRequirementTable($projectObj) {
//we want to display requirement Name, Priority, Parameter, Subtask Title 
        $output = "";
        if ($projectObj) {
            $output .= '<table class="width100" cellspacing="1">';
            $output .= '<caption>Current Project</caption>';
            $output .= ' <tr class ="header">';
            $output .=

                    '<td>Requirement</td><td>Priority</td><td>Parameter</td><td>Subtask Title</td>';
            $output .= '</tr>';
            foreach ($projectObj->tasks as $task) {

                foreach ($task->subtasks as $subtask) {
                    $output .= ' <tr class ="field">';
                    $output .= "<td>$subtask->reqName</td><td>$subtask->reqPriority</td><td>$subtask->paramName</td><td>$subtask->title</td>";
                    $output .= '</tr>';
                }
            }
            $output .= '</table>';
        }
        return $output;
    }

    function getActiveProjectsTable($fy) {
//Get active projects data
        $activeProjectsResult = getProjectsData($fy, "approved");
//get active projects html text
        $activeProjectsText = getProjectsShortSummaryTableText($activeProjectsResult, " Current $fy Projects");
//display returned html
        $output .= $activeProjectsText;
    }

    /**
     * Returns the html test for a project long summary table (WBS, title, start, end, status, cost, Funding Org, Submit Date)
     * @param type $result the mysql result for the desired projets to display
     * @param type $title the caption for the table. If NULL caption = Projects
     * @param type $approve if true then displays the approve/disapprove information
     * @param type $totalAllocated total $$$ available for the fy
     * @return string
     */
    function getProjectsShortSummaryTableText($result, $title = NULL, $approve = NULL, $totalAllocated = NULL) {
        $output = "";
        if ($result && $result->num_rows > 0) {
            $row = mysqli_fetch_assoc($result);
            $fy = getFYFromMysqlDateFormatStartDate($row['startDate']);
            $output .= '<table class="width100" cellspacing="1">';
            if ($approve) {
                $output .='<col width="4%"><col width="20%"><col width="8%"><col width="8%"><col width="8%"><col width="6%">
                       <col width="17%"><col width="10%"><col width="22%"><col width="5%">';
            }
            if ($title) {
                $output .= '<caption>' . $title . '</caption>';
            } else {
                $output .= '<caption>' . $fy . ' Projects</caption>';
            }

            if ($approve) {
                $output .= getShortSummaryHeaderWithApprovalColumns();
            } else {
                $output .= getShortSummaryHeader();
            }

            $counter = 0;
            do {
                $curProjectID = $row['projectID'];
                $wbsString = getFieldGivenAnID("wbs", "wbsID", $row['wbsId'], "wbsString");
                $output .= ' <tr class="field">';
                $output .= ' <td>';
                $output .= '<a class="black" href="projectController.php?projectId=' . $curProjectID . '">' . $wbsString . '</a>';
                $output .= ' </td>';
                $output .= ' <td>';
                $output .= $row['title'];
                $output .= ' </td>';
                $output .= ' <td>';
                $output .= $row['fy'];
                $output .= ' </td>';
                $output .= ' <td>';
                $output .= $row['cost'];
                $output .= ' </td>';

                if ($approve) {
                    $output .= ' <td>';
                    $output .= $row['approvedCost'];
                    $output .= ' </td>';
                    $output .= ' <td>';
                    if ($totalAllocated == 0) {
                        $output .= "N/A";
                    } else {
                        $output .= round($row['approvedCost'] / $totalAllocated, 2) * 100;
                    }
                    $output .= ' </td>';
                    $output .= ' <td class="field2">';
                    $output .= getFormInputElementText('radio', "group $counter", "10%", "approve", NULL, "approveRadio", "checked");
                    $output .= "Approve<br>";
                    $output .= getFormInputElementText('radio', "group $counter", "10%", "disapprove", NULL, "approveRadio");
                    $output .= "Disapprove";
                    $output .= ' </td>';
                    $output .= ' <td class="field2">';
                    if ($row['approvedCost'] === 0) {
                        $output .= getFormInputElementText("text", "textFieldAmountApproved $counter", "96%", $row['cost']);
                    } else {
                        $output .= getFormInputElementText("text", "textFieldAmountApproved $counter", "96%", $row['approvedCost']);
                    }
                    $output .= ' </td>';
                    $output .= ' <td class="field2">';
                    $output .= getFormInputElementText("text", "textFieldDisapproveComments $counter", "98%");
                    $output .= ' </td>';
                    $output .= ' <td class="field2">';
                    $output .= getHiddenFieldText("wbs$counter", $row['wbsId']);
                    $output .= getFormInputElementText("submit", "submit $counter", NULL, "Submit Decision", "return myFunction(this.value)");
                    $output .= ' </td>';
                } else {
                    $output .= ' <td>';
                    $output .= 'spent';
                    $output .= ' </td>';
                }
                $output .= ' </tr>';
                $counter++;
            } while ($row = mysqli_fetch_assoc($result));
            $output .= '</table>';
        } else {
            $output .= "<h2 class=\"centered\">There are no proposals for the selected year</h2>";
        }
        return $output;
    }

    function getProjectGradingTable($projectGradingResult, $title, $cost) {
        $colWidth = 100 / 9;
        $output = "";
        $output .= '<ul>';
        $output .= '<li> <h2>' . $title . ' ($' . $cost . ')</h2></li>';
        $output .= "<table><col width=\"20%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\"><col width=\"$colWidth%\">";
        $output .= '<tr class="header">';
        $output .= '<td>Name</td>';
        $array = getGradingCategoryArray();
        for ($i = 0; $i < sizeof($array); $i++) {
            $output .= "<td>$array[$i]</td>";
        }
        $output .= '</tr>';
        $personID = -1;
        $gradeObj = new gradingClass();

        while ($row = mysqli_fetch_array($projectGradingResult)) {
            $category = $row['subType'];
            $score = $row['value'];
            $comments = $row['notes'];
            $curPersonID = $row['personId'];
            if ($personID != $curPersonID) {
                $output .= '</tr>';
                $output .= '<tr class="field">';
                $output .= '<td>';
                $output .= getPersonNameStringFromID($curPersonID);
                $output .= '</td>';
            }
            $personID = $curPersonID;
            $tdTooltip = "title = \"$comments\"";
            $output .= "<td $tdTooltip>$score</td>";
            if (!is_nan($score)) {
                $gradeObj->addGrade($category, $score);
            }
        }
//end row here??
        $output .= '</tr>';
        $output .= '<tr class="blue"><td>Average</td>';
        for ($i = 0; $i < sizeof($array); $i++) {
            $output .= "<td>";
            $output .= $gradeObj->getAverage($array[$i]);
            $output .= "</td>";
        }
        $output .= '</tr>';
        $output .= '</table>';
        $output .= '</ul>';
        return $output;
    }

//MISC**************************************************************************


    function getProjectStartOfOrderedList($projectTitle) {
        return '<ul id="ulist"><h1 class="centered">' . $projectTitle . '</h1>';
    }

    function getFlagListItem($text) {
        return '<li class="red">' . $text . '</li><br>';
    }

    function getWbsDuplicateErrorListItem($wbs) {
        return '<li class="red">WBS selected was a duplicate so the new WBS is ' . $wbs . '</li><br>';
    }

    static function getShortSummaryHeaderWithApprovalColumns() {
        $output = "";
        $output .= '<col width="4%"><col width="30%"><col width="7%"><col width="20%"><col width="20%"><col width="10%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td>Title</td>';
        $output .= '     <td>Fiscal Year</td>';
        $output .= '     <td>Proposed ($K)</td>';
        $output .= '     <td>Approved ($K)</td>';
        $output .= '     <td>% Funds</td>';
        $output .= '     <td class="header2">Approve/Disapprove</td>';
        $output .= '     <td class="header2">Amount ($K)</td>';
        $output .= '     <td class="header2">Comments</td>';
        $output .= '     <td class="header2">Submit</td>';
        $output .= ' </tr>';
        return $output;
    }

    static function getShortSummaryHeader() {
        $output = "";
        $output .= '<col width="6%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td>Title</td>';
        $output .= '     <td>Fiscal Year</td>';
        $output .= '     <td>Cost</td>';
        $output .= '     <td>Spent</td>';
        $output .= ' </tr>';
        return $output;
    }

    function getProjectGradingList($projectGradingResult, $title) {
        $output = "";
        $output .= '<ul>';
        $output .= '<li> ' . $title . '</li>';
        $output .= '<ul>';
        while ($row = mysqli_fetch_array($projectGradingResult)) {
            $category = $row['subType'];
            $score = $row['value'];
            $comments = $row['notes'];
            $output .= "<li>$category ($score)</li>";
        }
        $output .= '</ul>';
        $output .= '</ul>';
        return $output;
    }

    /**
     * Gets the html project summary table (could be 1 or more projects)
     * @param type $result the result resource for 1 or more projects the db.
     */
    function getProjectSummaryTable($projectObjArray) {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Project Summary</caption>';
        $output .= '<col width="6%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td>Title</td>';
        $output .= '     <td>Fiscal Year</td>';
        $output .= '     <td>Status</td>';
        $output .= '     <td>Cost ($K)</td>';
        $output .= '     <td>Funding Org</td>';
        $output .= '     <td>Submit Date</td>';
        $output .= ' </tr>';

        foreach ($projectObjArray as $curProject) {
            $output .= ' <tr class="field">';
            $output .= ' <td><a class="black" href="mainPage.php?request=project&projectId=' . $curProject->ID . '&action=viewProjectDetails">' . $curProject->wbsString . '</a></td>';
            $output .= " <td>$curProject->title</td>";
            $output .= " <td>$curProject->fy</td>";
            $output .= ' <td>' . getStatusHumanReadableString($curProject->status, 'project') . '</td>';
            $output .= " <td>$curProject->proposedCost</td>";
            $output .= " <td> $curProject->fundingOrg</td>";
            $output .= " <td>$curProject->submitDate</td>";
        }
        $output .= getCloseTag("table");
        return $output;
    }

//static
    static function updateProjectStatusStatic($projectID, $status) {
        $sqlUpdate = "UPDATE project SET status='$status' WHERE projectID=$projectID";
        return executeUpdate($sqlUpdate);
    }

    static function updateNewProjectStatusFromOldStatic($projectID) {
        $oldStatus = getStatus("project", $projectID);
        //echo $oldStatus . '<br>';
        if (strcmp("taskSubmit", $oldStatus) === 0 || strcmp("nonlaborRequired", $oldStatus) === 0) {
            if (!projectModelClass::doesProjectHaveAtLeastOneTask($projectID)) {
                //echo $oldStatus . ' boom <br>';
                projectModelClass::updateProjectStatusStatic($projectID, "created");
            } else if (projectModelClass::doesEachTaskHaveASubtask($projectID)) {
                $nonLabor1 = getFieldGivenAnID('nonlaborcost', 'projectId', $projectID, 'proposedCost');
                //echo "Non: $nonLabor1";
                if (strcmp($nonLabor1, "-1") === 0) {
                    projectModelClass::updateProjectStatusStatic($projectID, "nonlaborRequired");
                } else {
                    projectModelClass::updateProjectStatusStatic($projectID, "subtaskSubmit");
                }
            } else {
                projectModelClass::updateProjectStatusStatic($projectID, "taskSubmit");
            }
        } else if (strcmp($oldStatus, "created") === 0) {
            projectModelClass::updateProjectStatusStatic($projectID, "taskSubmit");
        }
//others?
//catch a bad one if a status change is requested and not all tasks have a subtask
    }

    static function doesProjectHaveAtLeastOneTask($projectID) {
        $taskResult = executeSelect("SELECT taskID from task WHERE projectID=$projectID");
        if ($taskResult && $taskResult->num_rows > 0) {
            return true;
        } else {
            return false;
        }
    }

    static function doesEachTaskHaveASubtask($projectID) {
        $taskResult = executeSelect("SELECT taskID from task WHERE projectID=$projectID");
//echo 'tasks: '. $taskResult->num_rows .'<br>';
        if ($taskResult) {
            while ($row = mysqli_fetch_array($taskResult)) {
                $taskID = $row['taskID'];
                $stResult = executeSelect("SELECT subtaskID from subtask WHERE taskID=$taskID");
//echo 'subtasks: '. $stResult->num_rows .'<br>';
                if (!$stResult || $stResult->num_rows === 0) {
//echo 'false';
                    return false;
                }
            }
        } else {
//echo 'false';
            return false;
        }
//echo 'true';
        return true;
    }

    /**
     * Grabs the cost of each task adds them up and sets the project cost for the given projectID
     * @param type $projectID
     * @param type $costType (proposedCost, approvedCost, actualCost)
     * @return boolean
     */
    static function updateProjectCostStatic($projectID, $costType) {
        $result = executeSelect("SELECT $costType, status, duration FROM task WHERE projectID=$projectID");
        $projectCost = 0;
        $projectDuration = 0;
        if ($result) {
            //iterate through the tasks and add them up
            while ($row = mysqli_fetch_assoc($result)) {
                $status = $row['status'];
                if (strcmp("inactive", $status) !== 0) {
                    $projectCost += $row["$costType"];
                    $projectDuration += $row['duration'];
//if cost == 0 then there are 0 subtasks related to a task so lets change the status
//It could mean that they did not insert a performer for this subtask -- catch this error?
//                    if ($row['proposedCost'] == 0) {
//                        projectModelClass::updateProjectStatusStatic($projectID, "taskSubmit");
//                    }
                }
//echo $projectCost . '<br>';
            }
        } else {
            echo 'Error finding project ' . $projectID . '<br>';
            return false;
        }
//query non labor costs
        $sqlSelect = "SELECT proposedCost FROM nonlaborcost WHERE projectID=$projectID";
        $result2 = executeSelect($sqlSelect);
        if ($result2) {
            //iterate through them and add them up
            while ($row = mysqli_fetch_assoc($result2)) {
                if (strcmp($row['proposedCost'], "-1") === 0)
                    continue;
                $projectCost += $row['proposedCost'];
            }
        } else {
            echo 'Error finding project ' . $projectID . '<br>';
            return false;
        }
        if (executeUpdate("UPDATE project SET $costType=$projectCost, duration=$projectDuration WHERE projectID=$projectID")) {
            return true;
        }
        return false;
    }

}

?>
